Jump to content
Larry Ullman's Book Forums

Not Able To Delete An Image File


Recommended Posts

Well, here's the code:

function delete_file($which_one) {
if (unlink($which_one)) {
echo "$which_one deleted.";
} else {
echo "$which_one: delete failed.";
}
}

 

Here's the error:

 

Warning: unlink( photos/butterflyMilkweedweb.jpg ) [function.unlink]: No such file or directory in /ApacheServer/ApacheDocRoot/sites_in_progress/crc/view_photos.php on line 16

photos/butterflyMilkweedweb.jpg : delete failed.

 

I checked and found that there IS a directory "photos" on the same level as the file view_photos.php.

In that directory is butterflyMilkweedweb.jpg.

So, the path "photos/butterflyMilkweedweb.jpg" should be correct.

This also does not work: "/photos/butterflyMilkweedweb.jpg"

... something I'm not seeing here.

Link to comment
Share on other sites

Thank you. Yes, you are correct. It is what I thought had to be but careful examination didn't reveal it to me as the path names of those files to be deleted seemed to match what was in the variable. However, there is always the unseen that needs to be checked if all else fails so I tried trimming each variable in the array before using it as the path name of the file to be deleted. That worked.

 

I wasn't sure how a space worked its way into the pathname in the file reading code:

while (true == ($entry = $d->read())) {
if ($entry !== "." && $entry !== ".."){
$entry = "photos/".$entry;
//etc

 

however this line (I just picked up on it), seems pretty suspect to me:

 

echo '<td> delete this image:<input name="imageNames[]" value = " '.$entry.' " type="checkbox"/><br />

Link to comment
Share on other sites

 Share

×
×
  • Create New...