Home >Backend Development >PHP Tutorial >php unlink delete related issues_PHP tutorial
php unlink deletion problem
When deleting pictures
For example: unlink('abcdef.jpg');
This way you can delete it normally;
But the file name cannot be deleted when it is read from the database
fn=$rs['abc'];
unlink($fn);
It cannot be deleted. Have any experts encountered such a situation?
Prompt message:
Warning: unlink(user_logo/d4d84f383714d5f3.jpg) [function.unlink]: No such file or directory in
------Solution--------------------
Didn’t he make it very clear?
No such file or directory No such file or directory
------Solution--------------------
Error message file does not exist
It should be that the path is wrong
------Solution--------------------
First check whether the file exists and then delete it
The warnings are that the file or directory does not exist
if(file_exists($fn)){
unlink($fn);
}
------Solution--------------------
Look at your user_logo/ directory to see if this file exists in this directory
If not, then delete it. If yes, delete it. Add a judgment
if(file_exists($fn)){//The file exists
//todo delete
}