kev wood Posted April 24, 2008 Share Posted April 24, 2008 does any body no where i am going wrong with this code i keep getting an error message back saying Warning: unlink(): No such file or directory in /home/acmeart/public_html/mercury/upload.php i am using a variable with the path to the image stored in to it and using this in the unlink. can this be done. my code on this looks like this. unlink($broad1name2); //we will give an unique name, for example the time in unix time format $image_name=image1.'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $broad1name="image/".$image_name; $broad1name2="image/thumbs/thumb_".$image_name; $copied = copy($_FILES['broad1_image']['tmp_name'], $broad1name); $copied = copy($_FILES['broad1_image']['tmp_name'], $broad1name2); $sql="INSERT INTO images_broad (broad1) VALUES ('$broad1name2')"; $query = mysql_query($sql); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; Link to comment https://forums.phpfreaks.com/topic/102723-unlink/ Share on other sites More sharing options...
SharkBait Posted April 24, 2008 Share Posted April 24, 2008 try using something like if(file_exists($broadlname2)) { unlink($boardname2); } else { echo "File cannot be found"; } Link to comment https://forums.phpfreaks.com/topic/102723-unlink/#findComment-525997 Share on other sites More sharing options...
conker87 Posted April 24, 2008 Share Posted April 24, 2008 It looks like you're unlinking a file before you've actually uploaded it. If you checking to see if the file exists already, then do what SharkBait has but without an else. Link to comment https://forums.phpfreaks.com/topic/102723-unlink/#findComment-526060 Share on other sites More sharing options...
kev wood Posted May 6, 2008 Author Share Posted May 6, 2008 the files have already been uploaded on a different page i have checked on the server i have code now which is working fine i will post it up here so everyone can see. $fileToRemove2 = 'www.acmeart.co.uk/mercury/image/thumbs/thumb_image2.'.'.$extension'; $exts = array('jpg', 'png', 'gif', 'jpeg'); foreach($exts as $ext) { if (file_exists($fileToRemove2.'.'.$ext)) { @chmod(0777, $fileToRemove2.'.'.$ext); } @unlink($fileToRemove2); } Link to comment https://forums.phpfreaks.com/topic/102723-unlink/#findComment-534219 Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 All you're doing is suppressing the errors...But the problem is easily fixable. Whatever. =P Link to comment https://forums.phpfreaks.com/topic/102723-unlink/#findComment-534237 Share on other sites More sharing options...
Dathremar Posted May 6, 2008 Share Posted May 6, 2008 I think that the problem is the path. So make a double check on what goes into the unlink command and always use the file_exists command with unlink, that will solve some unnecessary head aches cheers Link to comment https://forums.phpfreaks.com/topic/102723-unlink/#findComment-534294 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 the problem was with the absolute path if file exists only works with relative paths once that was changed it worked fine. Link to comment https://forums.phpfreaks.com/topic/102723-unlink/#findComment-535785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.