Link to home
Start Free TrialLog in
Avatar of jristov
jristov

asked on

PHP unlink() -- if the file delete is unsuccessful.......

...is there a way around it, perhaps by the PHP version of "error handling", etc.?

I know that unlink will simply return a value of false (0) if the delete is unsuccessful, however (at least in my case) it will also generate a PHP error message of "permission denied", evidently because the user still has that document (a PDF generated by the pdftk.exe executable) open in the browser.

I need some way, if possible, to know in advance if the unlink is going to be unsuccesful, or otherwise a way to simply skip the unlink operation, without an error message, if it will be unsuccessful. Any ideas?
Avatar of PragmatiCoder
PragmatiCoder

It doesn't matter if the user has the document opened in his browser, cause it's already loaded in memory, so that's not the problem.

Try to do a chmod($path_to_file, 777) before deleting the file, that way you ensure that php will be able to delete the file
ASKER CERTIFIED SOLUTION
Avatar of Derokorian
Derokorian
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,
just an addon to both EE comments. Check the owner of the file. some times we provide the client to dump or use the file from different owner and try to delete it with different owner.
use 'chown' for it .
ya @ will suppress the errors but try to avoid its use. even after doing the above procedure if it fails.
Than try for it.

Check the path of files which has to be deleted
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jristov

ASKER

I've requested that this question be deleted for the following reason:

abandoned long ago
I believe there were perfectly good answers given here and here.