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

Link to comment
Share on other sites

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.

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.