php directory

Discussion in 'PHP' started by jpinheiro, Aug 8, 2008.

  1. #1
    how can i make a php file list all files in directory
    but with features like this

    I need a Display of each file like this

    Example:


    Displayed Filename1 - filesize - (Rename Button) (Delete File button)
    Displayed Filename2 - filesize - (Rename Button) (Delete File button)
    Displayed Filename3 - filesize - (Rename Button) (Delete File button)
    Displayed Filename4 - filesize - (Rename Button) (Delete File button)
    Displayed Filename5 - filesize - (Rename Button) (Delete File button)

    And it keeps going is this possible

    they have things like this in website hosts they have a page where you can manage files
     
    jpinheiro, Aug 8, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Read all files into an array, then loop through it, use each item as filename and pass it to filesize().

    That's the basic stuff. Then create links next to each file, and use the unlink() function to delete files. Or rename() to rename it.

    This should get you started. Give it a try and show us what you've tried if you get stuck at some point.
     
    nico_swd, Aug 8, 2008 IP
  3. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #3
    thanks i am trying to learn this stuff is just very confusing :D

    ill give it a try
     
    jpinheiro, Aug 8, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    That's the best way of learning. Try, and ONLY ask if you're really stuck. ;)
     
    nico_swd, Aug 8, 2008 IP
  5. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Ok heres where i am so far but delete doesnt work

    
    <b>FileName</b> - <b> File Size </b>
    <br>
    <br>
    
    <?php
    foreach (glob("*.php") as $filename) {
        echo "$filename size " . filesize($filename) . " <a href=&quot;unlink($filename);&quot;>Delete</a> <br> \n";
    }
    ?>
    PHP:
    This is the Output:

    FileName - File Size

    ban.php size 357 Delete
    banlist.php size 357 Delete
    clearlog.php size 1675 Delete
    config.php size 32 Delete
    download.php size 515 Delete
    download1.php size 83 Delete
    index.php size 1029 Delete
    log.php size 1902 Delete
    mailto.php size 310 Delete
    test.php size 222 Delete
    testing.php size 1838 Delete

    The Delete button links look like this:

    http://cynscriptz.com/demo/dlscript/unlink(ban.php);
    http://cynscriptz.com/demo/dlscript/unlink(banlist.php);
    http://cynscriptz.com/demo/dlscript/unlink(clearlog.php);

    and goes on like this but the links dont work :( why not
     
    jpinheiro, Aug 8, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    You have to pass the filename to a new or the same page, and THEN delete it.

    Eg:
    
    "<a href=\"file.php?filename={$filename}\">Delete</a>"
    
    // And in the other or same file:
    if (isset($_GET['filename']))
    {
        unlink($_GET['filename']);
    }
    
    PHP:
    ... this is just an example. It's not secure for public use.
     
    nico_swd, Aug 8, 2008 IP
  7. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Ok now it works the way you made it but

    i tried to add a javascript promt but now it doesnt work ?

    
    <b>FileName</b> - <b> File Size </b>
    <br>
    <br>
    
    <?php
    foreach (glob("*.php") as $filename) {
        echo "$filename size " . filesize($filename) . "<a href=\"deletefile.php?filename={$filename}\" onClick="javascript:return confirm('Are you Sure you want to delete File')">Delete File</a><br>";
    }
    ?>
    
    PHP:
     
    jpinheiro, Aug 8, 2008 IP
  8. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #8
    ok i solved the problem on my own :D it works fully functional
     
    jpinheiro, Aug 8, 2008 IP