brem13 Posted March 10, 2009 Share Posted March 10, 2009 ive got a script that deletes pictures if the checkbox is checked and it works fine, it deletes the picture, the thumbnail and the row from the database, but it still loops through and looks for the picture and since its not there it gives me an unlink..cannot find the file error foreach($aPics as $PicKey => $picname) { if(array_key_exists($PicKey, $aComments)) { if (isset($delete[$PicKey])){ mysql_query("DELETE FROM $userlow WHERE picture='$picname'") or die(mysql_error()); unlink($picname); unlink("thumbs/".$picname); }//end iff }//end foreach error: unlink(1234907747.jpg) [function.unlink]: No such file or directory in editgall.php on line 57 Quote Link to comment https://forums.phpfreaks.com/topic/148849-solved-unlink-file-error/ Share on other sites More sharing options...
premiso Posted March 10, 2009 Share Posted March 10, 2009 Use file_exists before unlink If it exists try to unlink, if not then it got deleted at some point in time. Quote Link to comment https://forums.phpfreaks.com/topic/148849-solved-unlink-file-error/#findComment-781618 Share on other sites More sharing options...
socratesone Posted March 10, 2009 Share Posted March 10, 2009 You could check if the file exists before you call unlink. if(file_exists($picname)){ unlink($picname); }else{echo 'file not found';} if(file_exists("thumbs/".$picname)){ unlink("thumbs/".$picname); }else{echo 'thumb not found';} If you're getting the echo'd error message, make sure that the path is correct, as well. Quote Link to comment https://forums.phpfreaks.com/topic/148849-solved-unlink-file-error/#findComment-781624 Share on other sites More sharing options...
brem13 Posted March 10, 2009 Author Share Posted March 10, 2009 thank you guys!!! Quote Link to comment https://forums.phpfreaks.com/topic/148849-solved-unlink-file-error/#findComment-781633 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.