View Full Version : File Manager Problem

02-07-2006, 05:04 PM
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>";

02-07-2006, 06:10 PM
>> You don't need to put ';' at the end?
also can you put it in
code here

02-07-2006, 06:43 PM
Well, why not pass a query string?

print "<a href=\"delete.php?file=$file\">Delete</a>";

[edit:] You would the of course do something like this in delete.php:


Also, it would be handy to make sure the user wanted to delete the file for sure before hand.