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. Quote Link to comment 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()); Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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()? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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"); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.