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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.