Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Post Php List Files In Dir

    Hey,

    Making a script... the usual yada yada... (sounds like yoda, odd... anyways)....

    I made an uploader form, and now I need a script that displays all the files in the upload directory in a simple table but am clueless as to how to do it....? I came across a script that does what I wanted but i couldn't get it to work... here's the snippet for the file list part:

    PHP Code:
    $upload_dir '../uploads/';
    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file)) {
          
    $filelist .= "<a href='$upload_dir$file'>".$file."</a>";
          if (
    $DELETABLE)
            
    $filelist .= " <a href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
          
    $filelist .= "<sub><small><small><font color=grey>  ".date("d-m H:i"filemtime($upload_dir.$file))
                       .
    "</font></small></small></sub>";
          
    $filelist .="<br>";
       }

    So would anyone be able to give me a good script that would do what I want?

    Thanks in advance!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #2
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    Quote Originally Posted by Troy297 View Post
    Hey,

    Making a script... the usual yada yada... (sounds like yoda, odd... anyways)....

    I made an uploader form, and now I need a script that displays all the files in the upload directory in a simple table but am clueless as to how to do it....? I came across a script that does what I wanted but i couldn't get it to work... here's the snippet for the file list part:

    PHP Code:
    $upload_dir '../uploads/';
    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file)) {
          
    $filelist .= "<a href='$upload_dir$file'>".$file."</a>";
          if (
    $DELETABLE)
            
    $filelist .= " <a href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
          
    $filelist .= "<sub><small><small><font color=grey>  ".date("d-m H:i"filemtime($upload_dir.$file))
                       .
    "</font></small></small></sub>";
          
    $filelist .="<br>";
       }

    So would anyone be able to give me a good script that would do what I want?

    Thanks in advance!
    This will list all files in a directory and put them in a table ~ very simplified ... If you want to display only certain types of files you can put the extension in (*.*) like (*.mp3), etc ...

    PHP Code:
    <?php

    foreach (glob("*.*") as $filename) {
       
    $files = array($filename => $filename);

    $list .= "\n".'<tr><td>' $filename .'</td></tr>'."\r\n";

    }

    echo 
    '<table>';

    echo (
    $list);

    echo 
    '</table>';

    ?>
    Regards ~

  • #3
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks! That works great.... but how do i specify a remote directory?
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #4
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Troy297 View Post
    Thanks! That works great.... but how do i specify a remote directory?
    ... like this ...

    PHP Code:
    glob('/pathto/files/*.*'); 

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by warlord View Post
    ... like this ...

    PHP Code:
    glob('/pathto/files/*.*'); 
    >.<
    Thats a relative directory. Glob does not work on remote directory.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Ya lol... the relative directory is what I meant... I had tried to edit the code previously except I kept trying the following instead of the right way!

    PHP Code:
    glob('*/pathto/files/*'); 
    Anyways got it figured out now. Thanks for all the help! +Rep for all!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •