[RESOLVED] Delete previously uploaded file from server?
Ok, so I have a page where an authorized user can upload a file... there is also a list of uploaded files (each has info in the database) and a "delete" check-box to remove it... It removes the info from the database, but how do I remove the file itself from the "docs" folder on the server?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
I tried that, but it's not working. There's a "close file" thingy that gets put in before that tries to open the file and returns the error "can't open file" -- probably because the file is a PDF... should the file-type be causing a problem with the unlink() function?
Here's what I've got to delete the file:
PHP Code:
$delFile = "docs/".$rowfile; $fh = fopen($delFile, 'w') or die("can't open file"); fclose($fh); unlink($delFile);
...and it just returns the "can't open file" error.
Well, if it's dieing on that line, then the following lines never get executed. So you might want to add some debug code to find out why the fopen is failing.
PHP Code:
$delFile = "docs/".$rowfile;
if( ! file_exists($delFile)) {
die("Cannot find file '$delFile'");
}
if( ! is_writable($delFile)) {
die("File '$delFile' is not writable");
}
ini_set('display_errors', true);
error_reporting(E_ALL);
$fh = fopen($delFile, 'w') or die("can't open file");
fclose($fh);
unlink($delFile);
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Warning: fopen(docs/) [function.fopen]: failed to open stream: Is a directory in /home/mywebsite/public_html/sites/misc/testfolder/adm_docs.php on line 142
can't open file
Except that "$rowfile" is created just a few lines up from the filename from the database. It should work, but it doesn't. I'm going to try tweaking a couple of other things & then I'll get back to you guys. Thanks a ton for the help thus far.
Bookmarks