timmah1 Posted June 10, 2008 Share Posted June 10, 2008 Can someone tell me why this isn't working? $filepath = "$config_basedir/photos/$_POST[photo_path]"; unlink($filepath); The error I get is this Warning: unlink(/photos/1488659011.jpg ) [function.unlink]: No such file or directory in /home/kinder/public_html/main/delete_Photo.php on line 15 It deletes from the database, but won't delete of the site. Yes, the "photos" folder is 0777 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/ Share on other sites More sharing options...
slawrence10 Posted June 10, 2008 Share Posted June 10, 2008 T'm afraid I don't have very advance knowledge of PHP but I'll try and help at the moment you are trying to delete /photos/1488659011.jpg from /home/kinder/public_html/main/delete_Photo.php.... but delete_Photo.php is a page not a directory. What directory are you trying to delete from... Yes, the "photos" folder is 0777 where does this relate in your code? Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561649 Share on other sites More sharing options...
timmah1 Posted June 10, 2008 Author Share Posted June 10, 2008 Correct. I am trying to delete the .jpg from the photos directory Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561651 Share on other sites More sharing options...
slawrence10 Posted June 10, 2008 Share Posted June 10, 2008 I understand that but where is the photo directory in relation to your page delete_Photo.php Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561659 Share on other sites More sharing options...
timmah1 Posted June 10, 2008 Author Share Posted June 10, 2008 Did I not put this $config_basedir/photos/$_POST[photo_path] $_POST[photo_path] is the actual photo name Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561660 Share on other sites More sharing options...
ibolui Posted June 10, 2008 Share Posted June 10, 2008 i m not too sure, someone correct me if i m wrong. i would think that unlink(/photos/1488659011.jpg) means deleting 1488659011.jpg from a photo dir, a subfolder where delete_Photo.php resided. meaning if delete_Photo.php is in dir main, then unlink is trying to delete main/photos/1488659011.jpg. hence you may like to check if the path is correct. also, unlink($filepath) returns unlink(/photos/1488659011.jpg), which may means $config_basedir is initialised.. Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561667 Share on other sites More sharing options...
timmah1 Posted June 10, 2008 Author Share Posted June 10, 2008 delete_Photo.php is in the main directory Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561670 Share on other sites More sharing options...
timmah1 Posted June 10, 2008 Author Share Posted June 10, 2008 ok. I've tried this $myFile = "/home/kinder/public_html/main/photos/$_POST[photo_name]"; $fh = fopen($myFile, 'w') or die("can't open file"); fclose($fh); unlink($myFile); The code goes with no problem, except that it still does not delete the file. I get no errors at all. Anybody have any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561738 Share on other sites More sharing options...
ibolui Posted June 10, 2008 Share Posted June 10, 2008 i tried some simple test. firstly, if the file does not exist, your codes will not produce the die error. so if photo is in the same dir as delete_photo.php, try this.. unlink('./photo.jpg'); because as your first post said, "No such file or directory" which i assume that the path is wrong. Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561750 Share on other sites More sharing options...
timmah1 Posted June 10, 2008 Author Share Posted June 10, 2008 the file delete_photo.php is not in the same directory Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561752 Share on other sites More sharing options...
ibolui Posted June 10, 2008 Share Posted June 10, 2008 then try navigating to the dir where photo is in. say delete_photo.php is in main dir, photo.jpg is in main then should be something like unlink('./photo.jpg'); if delete_photo.php is in main dir, photo.jpg is in main/photos then should be something like unlink('./photos/photo.jpg'); try to navigate using . or .. to point to the correct path Link to comment https://forums.phpfreaks.com/topic/109492-unlink-file/#findComment-561758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.