phpretard Posted February 21, 2009 Share Posted February 21, 2009 I am delteting a file from a directory and get this error. unlink(test.pdf) [function.unlink]: No such file or directory in... HOWEVER THE FILE IS BEING DELETED??? <? $docName=$_POST['docName']; $location=$_POST['location']; $id=$_POST['id']; $TheFile=$location; unlink($TheFile); $delete=mysql_query("DELETE FROM documents WHERE id='$id'"); ?> Can anyone explain this? Link to comment https://forums.phpfreaks.com/topic/146243-unlink-error/ Share on other sites More sharing options...
only one Posted February 21, 2009 Share Posted February 21, 2009 It's showing that error because the file doesn't exist. If it does exist and is being deleted. You could simply place an @ sign infront of the function to stop it showing any errors. Link to comment https://forums.phpfreaks.com/topic/146243-unlink-error/#findComment-767785 Share on other sites More sharing options...
CarbonCopy Posted February 21, 2009 Share Posted February 21, 2009 <?php $docName=$_POST['docName']; $location=$_POST['location']; $id=$_POST['id']; $TheFile=$location; if (file_exists($TheFile)) { unlink($TheFile); } else { echo "Sorry, but the file " . htmlentities($TheFile) . " does not exist"; } $delete=mysql_query("DELETE FROM documents WHERE id='$id'"); ?> Link to comment https://forums.phpfreaks.com/topic/146243-unlink-error/#findComment-767792 Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 It's not a good idea to use the @ sign because it masks errors instead of fixing them. There is the rare occasion when it should be used, but in this case, it would be better to figure out what exactly is happening. Link to comment https://forums.phpfreaks.com/topic/146243-unlink-error/#findComment-767796 Share on other sites More sharing options...
.josh Posted February 21, 2009 Share Posted February 21, 2009 So...you're saying that the file IS there, but php is saying it's not, but it IS being deleted anyway? Are you sure it was there in the first place? Or perhaps your code is being executed twice. Link to comment https://forums.phpfreaks.com/topic/146243-unlink-error/#findComment-767805 Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 Re-create the file and double check that it is definitely getting deleted. Link to comment https://forums.phpfreaks.com/topic/146243-unlink-error/#findComment-767807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.