Solved

How to list all files in a specific folder using php and hostgator server

Posted on 2011-09-20
6
305 Views
Last Modified: 2012-05-12
I am building a joomla website and need to list all of the files in a specific folder off of the root "public_html" folder.  For example, if I need to list all of the files in, say, "public_html/testdir".  What path would I have to pass to opendir() for access.  The website is currently sitting on a hostgator server.
0
Comment
Question by:rawcoder
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:MattJellings
ID: 36569535
Hi rawcoder,

Sorry, I'm not in a position to test the code below, however please give it a try and see if it achieves what you are looking to do

if ($handle = opendir($_SERVER['DOCUMENT_ROOT'] . '/testdir')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}

Open in new window

0
 

Author Comment

by:rawcoder
ID: 36569649
I tried that and received the following permission denied error:  "Warning: opendir(/home/hairupst/public_html) [function.opendir]: failed to open dir: Permission denied".  Is there anything special I need to do?  
0
 
LVL 13

Expert Comment

by:Andrew Derse
ID: 36569953
What is the exact script that you are posting in your file?

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 13

Accepted Solution

by:
Andrew Derse earned 500 total points
ID: 36570002
I believe you would need to write this:

 
<?php 

if ($handle = opendir($_SERVER['DOCUMENT_ROOT']."/joomlafolder/")) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file <br />";
        }
    }
    closedir($handle);
}

?>

Open in new window


joomlafolder being the directory that your site is installed in.  

If that still doesn't work, then you don't have full permissions to that directory for an anon user...
0
 
LVL 13

Expert Comment

by:Andrew Derse
ID: 36573305
Did any of the above help you?

To verify that it's a permission problem, you can alter the above scripts to drill further down into the directories.  I believe the images folder should be open to all users...

"/joomlafolder/images/"
0
 
LVL 4

Expert Comment

by:MattJellings
ID: 36579151
Does the "public_html/testdir" folder exist?  If not create it.

Also, as NUKIT said please make sure you have permission to read the folder you are trying to access.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Load google maps api into wordpress 5 37
unset shopping cart session 15 32
how to use a function in heredoc 5 23
How to convert my query to the proper format? 5 18
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now