Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-20
6
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
Andrew Derse earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
A big percent of today’s marketing activity is performed through the online environment. The marketing strategies that have existed a decade ago no longer relate to what’s happening today. We’re currently facing a revolutionary era, called the digit…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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