Katya S
Katya S

Reputation: 1353

Cannot unlink a file in PHP/Windows

I'm seeing a few questions raised on this topic, but looking around I have not managed to find a solution, unfortunately.

I'm running PHP5.3 with Apache2 on Windows Server 2008.

A PDF file is created by the script, and after being emailed needs to be deleted, thus:

unlink($filename);

The above code does not delete the file, but returns this error message:

[18-Mar-2013 10:56:06 UTC] PHP Warning: unlink(D:\mypath\temp\myfilename.pdf) [function.unlink]: Permission denied in D:\mypath\Controller\IndexController.php on line 554

Using exec/whoami I can see that the user is "nt authority\system"

Using fileperms function, and parsing it using code in Example2, I can see that the file has these permissions: 33206 -rw-rw-rw-

I have also checked the containing folder, and this system user has Full Control on that folder and its contents.

Could anyone suggest anything else to try to delete the file? Thanks in advance.

Upvotes: 3

Views: 5106

Answers (1)

Susheel
Susheel

Reputation: 1679

Very first answer should occur in mind when unable to delete: Use by another program or process.

Use flock when writing or performing exclusive operation on file.

Upvotes: 1

Related Questions