sixteh Posted February 16, 2008 Share Posted February 16, 2008 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 More sharing options...
ratcateme Posted February 16, 2008 Share Posted February 16, 2008 try adding this to the front of the file names dirname(__FILE__) also add this to the end of your query's to check for errors mysql_query("DELETE FROM downloads WHERE did='$id'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468444 Share on other sites More sharing options...
sixteh Posted February 16, 2008 Author Share Posted February 16, 2008 How do I implement dirname()? From what I can tell, dirname will simply give me the directory of a string, which I already know. I want to delete the file. Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468453 Share on other sites More sharing options...
ratcateme Posted February 17, 2008 Share Posted February 17, 2008 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 https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468531 Share on other sites More sharing options...
sixteh Posted February 17, 2008 Author Share Posted February 17, 2008 It doesn't appear to work. Do I change the contents of dirname()? Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468571 Share on other sites More sharing options...
ratcateme Posted February 17, 2008 Share Posted February 17, 2008 try adding this to your script to see if it is working right echo $filename; Scott. Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468651 Share on other sites More sharing options...
sixteh Posted February 17, 2008 Author Share Posted February 17, 2008 I've tried, but nothing is echoed - in fact, it just redirects me back despite the fact that I commented out the redirect. Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468939 Share on other sites More sharing options...
ratcateme Posted February 17, 2008 Share Posted February 17, 2008 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 https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-468958 Share on other sites More sharing options...
sixteh Posted February 17, 2008 Author Share Posted February 17, 2008 Okay, I got the echo to work but now it only shows the directory name with the trailing quest; there is no file name appended. Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-469051 Share on other sites More sharing options...
spfoonnewb Posted February 17, 2008 Share Posted February 17, 2008 Is that the whole script? Do you have a DB connection anywhere? Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-469056 Share on other sites More sharing options...
sixteh Posted February 17, 2008 Author Share Posted February 17, 2008 Yes, everything is connected and working fine. The db changes are fine, but the unlink doesn't work. Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-469074 Share on other sites More sharing options...
spfoonnewb Posted February 17, 2008 Share Posted February 17, 2008 Is the file writable (aka removable) by your apache group? unlink($filename) or die("Perms or Groups or Missing"); Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-469080 Share on other sites More sharing options...
sixteh Posted February 17, 2008 Author Share Posted February 17, 2008 Hmm I'm not sure why, but I rewrote it and now the script works. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/91424-troubles-with-unlink-with-a-database/#findComment-469108 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.