chop Posted November 20, 2012 Share Posted November 20, 2012 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 More sharing options...
Larry Posted November 21, 2012 Share Posted November 21, 2012 There's nothing I'm seeing either, but the error message clearly indicates that the file does not exist, so it is a path or name issue. Link to comment Share on other sites More sharing options...
chop Posted November 26, 2012 Author Share Posted November 26, 2012 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 More sharing options...
Larry Posted November 26, 2012 Share Posted November 26, 2012 Kudos for figuring it out and thanks for sharing the solution. In that echo line, you have a space before AND after the $entry value. Link to comment Share on other sites More sharing options...
Recommended Posts