I am trying to delete a file from the server using the unlink() function with php.
Here is my code:
$photo_to_delete = 'http://www.example.com/images/uploads/properties/197/IMG_0002.jpg';
unlink($photo_to_delete);
Here is the error message I am getting:
Warning: unlink() [function.unlink]: Unable to locate stream wrapper
in
/nfs/c09/h01/mnt/137110/domains/www.example.com/html/listers/edit_photos.php
on line 43
Line 43 is where I have the unlink() function is.
Why am I getting a ‘Unable to locate stream wrapper’ message when using unlink() in php?
I’m pretty sure you can’t delete a file remotely like that. Try using a relative path. Or even an absolute path (minus the
http://domain.compart).In other words:
Or better yet, if you’re going to use an absolute path, try prefixing it with
$_SERVER['DOCUMENT_ROOT'].