FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Displaying Files...





[FuN]goku
is there a php script for displaying files on my webspace like im made a file uploader but... is there a way to show the files that i upload on a php page??? sort of like apache.... im doing it for my forums so admins can upload small things.
rohan2kool
Yes you can.. Here is a small script for you:

Code:

$files = array();
$directories = array();

if($handle = opendir('.')) { //view files in current directory
   while(false !== ($file = readdir($handle)) {
      if(is_dir($file)) {
         $directories[] = $file;
      } else {
         $files[] = $file;
      }
   }
}


If everything goes fine.. you will have an array called $files and $directories with the filenames of the files and directories respectively inside the directory in which the php page was. Now, using a foreach loop you can output it to the screen the way you want in ur preffered style.
[FuN]goku
gives me this error
Quote:
Parse error: syntax error, unexpected '}' in /home/fungoku/public_html/ps/uploader/images/index.php on line 6

that is when i include the <?php ?> tags its on this line
Code:
while(false !== ($file = readdir($handle)) {
rohan2kool
Opps.. sorry. It is a small workaround:

change:

Code:

while(false !== ($file = readdir($handle)) {


to:

Code:

while(false !== ($file = readdir($handle))) {


i.e just add an extra ')' bracket to close the while loop. That's all.
[FuN]goku
ok.... no error but theres a blank page now..
BlackSkad
rohan2kool wrote:
Now, using a foreach loop you can output it to the screen the way you want in ur preffered style.


Just put this little thing under the script of rohan2kool
Code:
echo 'Directories:<br />';
foreach ($directories as $dir) {
    echo $dir . '<br />';
}
echo 'Files:<br />';
foreach ($files as $file) {
    echo $file . '<br />';
}
[FuN]goku
ahh k thank you works now ^^
rohan2kool
I did not give those foreach loops because I though you would like your own styles while outputting the file/directory list.
afracsass
Looks like very useful script.
I could use this script to see the file list of my sites
thanks,
Related topics
dot files
req: PHP to list files in directory, and link to them
Help: SQL error after uploading new files(thread updated)
Microsoft gunning for Adobe's PDF format?
How Spyware Works!!!
deleting all the original files
.rm files
Is it possible to upload music files to a website?
751 Useful Windows XP Files
Can I get my files off of my disable account
PHP has stopped displaying my nav
Installing files for East Asian languages on XP Pro.
displaying from array
Where can I host ico files?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.