I created a back end for a site using PHP..and i have file upload facility in dat
also i need to physically delete the files when user request
so pls tell me the code(functions) to do that
How to delete a file
Moderator: General Moderators
take a look at the unlink function on http://www.php.net
sample
do u have sample code for that??
Re: sample
rangasys wrote:do u have sample code for that??
Code: Select all
unlink("path/to/the/file.ext");there is example code on http://www.php.net for it as with most php functions, pimps code is fine
I was assuming you have the filename stored in a mysql database or similar, in which case you can just query the db loop over the results you want to delete, check they exists and delete them, not much to it really.
I was assuming you have the filename stored in a mysql database or similar, in which case you can just query the db loop over the results you want to delete, check they exists and delete them, not much to it really.
Code: Select all
// better get filenames from db
$this->sql = "SELECT * FROM filesWHERE fileId='".$fileId."'";
$this->result = mysql_query($this->sql);
$row = mysql_fetch_assoc($this->result);
// check for files
if(is_file("/files/".$row['filename'])){
// delete file
unlink("/files/".$row['filename']);
}