Jump to content

how to delete files?


herando

Recommended Posts

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'";
Link to comment
Share on other sites

$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.
Link to comment
Share on other sites

[!--quoteo(post=376962:date=May 25 2006, 06:27 AM:name=herando)--][div class=\'quotetop\']QUOTE(herando @ May 25 2006, 06:27 AM) [snapback]376962[/snapback][/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";
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.