Jump to content

Troubles with unlink() with a database.


sixteh

Recommended Posts

I'm running a script to modify a files system database where each row has an id, file name, and preview name assigned. The following script is accessed with .php?act=do_modd&id=x.

<?php
$dquery = mysql_query("SELECT * FROM downloads WHERE did='$id'");
$row = mysql_fetch_array($dquery);
$filename = "downloads/".$row['file'];
$previewname = "downloads/previews/".$row['preview'];
unlink($filename);
unlink($previewname);
mysql_query("DELETE FROM downloads WHERE did='$id'");
?>

I want the script to take the data from the table downloads to determine the which files (listed in the database under the columns "file" and preview") to unlink, then delete that row from the database. However, when running this script, neither occurs. The files remain and the database entry is still there, but I know that the code above is being run. I don't get any error messages. Any idea what's wrong?

 

Edit:

Fixed code tags.

Link to comment
https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/
Share on other sites

i found when uploading a file i had problems it didn't know where to put the uploaded file when i added dirname() it worked so adding this on to the start of your unlike command like this

 

$filename = dirname(__FILE__)."/downloads/".$row['file'];
$previewname = dirname(__FILE__)."/downloads/previews/".$row['preview'];
unlink($filename);
unlink($previewname);

it will delete using a full path

 

Scott.

are you sure you are editing the same file i was once editing a file i thought was on ftp when it was editing a file saved to the PC i was on because this sounds like a editing problem if you are still getting redirected even after commenting out the redirect.

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.