Jump to content


Photo

how to delete files?


  • Please log in to reply
2 replies to this topic

#1 herando

herando
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 May 2006 - 10:27 AM

i choose a file from a form field and upload to folder and write a file name to table. when i delete a row, it deletes only file names from table. how to delete a corresponding file when a row is deleted?

row delete line:

$sql_del="DELETE FROM $data_table WHERE id='$id'";


#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 25 May 2006 - 10:46 AM

$query = "SELECT * FROM $data_table WHERE id='$id'";
$result = mysql_query($query);

Set the filename variable with the value from the database, and then use:

unset($filename);

then delete the entry from the database.
wisewood: proven fact, I am both wise, and wooden.

#3 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 25 May 2006 - 12:46 PM

[!--quoteo(post=376962:date=May 25 2006, 06:27 AM:name=herando)--][div class=\'quotetop\']QUOTE(herando @ May 25 2006, 06:27 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
i choose a file from a form field and upload to folder and write a file name to table. when i delete a row, it deletes only file names from table. how to delete a corresponding file when a row is deleted?

row delete line:

$sql_del="DELETE FROM $data_table WHERE id='$id'";
[/quote]

I think what your looking for is:

$filename= "/tmp/test.file";
if(!unlink($filename)){
echo "file deleted";
}else{
echo "failed to delete file";
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users