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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Manager Problem

    I am writing a file manager script. I have come accross a problem. I use the following code to list all the files in the directory into a table, creating a new row for each file and displaying its information. Then at the end of each row for each file there is a "Delete" link. I want this link to just delete the file in the row its in, but i cant figure out how to track which "Delete" link it being pressed and which file in the table goes with it, anyone help? The delete text should goto delete.php but then how would i use this and pass the file name to the next page?

    // Create table for filenames
    print "<font size = \"2pt\" face=\"Arial\">";
    print "<table border=\"1\" width=\"100%\" id=\"table1\" bordercolorlight=\"#000000\" cellspacing=\"0\" cellpadding=\"0\" bordercolordark=\"#000000\">\n";
    print "<tr><td><b>Filename </b></td> <td><b>File Type</b></td> <td><b>File Permissions</b></td> <td><b>File Size</b></td> <td><b>Last Access</b></td> <td><b>Last Modified</b></td> <td><b>Last Changed</b></td></tr>";

    while (!(($file = readdir($openfolder)) === false)) { //current file = readdir (loop position) for the openfolder (while end of folder is false)
    if (is_dir("$dirname/$file")) { // if the file is a directory
    $filetype = "Folder";
    } else {
    $filetype = "File";
    }

    // Get the current file size in bytes
    $filesize = filesize($file);

    // Get the current file permissions
    $fileperms = fileperms($file);

    // Get info when file was last accessed
    $lastaccess = fileatime($file);

    // Get info when file last modified
    $lastmodified = filemtime($file);

    // Get info when file last changed
    $lastchanged = filectime($file);

    print "<font name=\"Arial\" size=\"2pt\" color=\"darkblue\">";
    print "<tr>\n";
    print "<td>";
    print "$file<br>";
    print "</td>\n";
    print "<td>";
    print "$filetype";
    print "</td>";
    print "<td>";
    substr(printf ('%o',$fileperms),-1,3); // Printf enables to display understandable values, %o to display integer use substr(string,strt,number)
    print "</td>";
    print "<td>";
    print "$filesize";
    print "</td>\n";
    print "<td>";
    print date(d . "/" . m . "/" . Y, $lastaccess);
    print "</td>";
    print "<td>";
    print date(d . "/" . m . "/" . Y, $lastmodified);
    print "</td>";
    print "<td>";
    print date(d . "/" . m . "/" . Y, $lastchanged);
    print "</td>";
    print "<td>";
    print "<a href=\"delete.php\">Delete</a>";
    print "</td>";
    print "</tr>\n";
    print "</font>";

    }
    closedir($openfolder); // once done close the folder

    // End the table
    print "</table>";
    print "</font>";
    ?>

  • #2
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    substr(string,strt,number)
    >> You don't need to put ';' at the end?
    also can you put it in [PHP]code here[/PHP]

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well, why not pass a query string?

    PHP Code:
    print "<a href=\"delete.php?file=$file\">Delete</a>"
    [edit:] You would the of course do something like this in delete.php:

    PHP Code:
    <?php
    unlink
    ($_GET['file']);
    ?>
    Also, it would be handy to make sure the user wanted to delete the file for sure before hand.
    Last edited by Mhtml; 02-07-2006 at 05:47 PM.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

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