Reputation: 216
image delete unlink() issue on localhost:
My Code Snippet (Not Working):
if(file_exists('./uploads/Property/'.$imgnm))
{
unlink('./uploads/Property/'.$imgnm);
}
My Code Snippet (Working):
if(file_exists('./uploads/Property/300X300/'.$imgthumbnm))
{
unlink('./uploads/Property/300X300/'.$imgthumbnm);
}
I checked $imgnm & $imgthumbnm variable values carefully.. values are correct
then why not image getting deleted in first code snippet, please suggest me changes or idea to resolve this issue
Upvotes: 0
Views: 91
Reputation: 721
If all is okay then surely issue is with variable $imgnm.. check it carefully
Upvotes: 1
Reputation: 377
You are using the @
operator. This tells the php interpreter to ignore all errors from the given statement. To see, what is going on, and why your code is not working, remove the @
before unlink
.
This will assure, that you will see any error that will be produced by the call, so it should tell you right away, what is wrong and you can try to fix the problem.
Usually, using the @
is considered a bad practice in modern php, instead I would recommend you to use a custom error handler to make errors produce exceptions. Then you can wrap your code in a try catch
construct and it will be much easier for you to actually handle, if something goes wrong.
Upvotes: 0