Jump to content

unlink file


timmah1

Recommended Posts

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

 

 

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.