php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23687 Permission denied error with unlink()
Submitted: 2003-05-18 16:19 UTC Modified: 2003-05-18 17:44 UTC
From: a dot eibach at gmx dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.2RC3 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: a dot eibach at gmx dot net
New email:
PHP Version: OS:

 

 [2003-05-18 16:19 UTC] a dot eibach at gmx dot net
Hi.

I can see this has been discussed multiple times in this forum: however, there's no real solution for it, it seems.

First my specs:

- Apache 1.3.27 (<- could that be it?)
- PHP 4.3.2 RC3 (PHP running as a *module* (dll))
- Win2k

I scanned the news groups about this problem, where lots of people claimed this to work. However, even such a simple script here:

<?php
if (!is_dir("thisisatest"))
{
 mkdir ("thisisatest");
}
else echo "Dir creation skipped. Dir already exists.";

echo "Waiting ...";

sleep(3);

echo "done.";

unlink ("thisisatest");

?>


fails on my system with a Permission denied error.
Tips to 'chmod' the current directory are fruitless, because this is WINDOWS and not UNIX and there are no permissions like this.
I do not intend to use OS-specific stuff like 'del' or 'rm', combined with the system() command.
I also tested with PHP 4.0.6 and also failed.

Warning: Unlink failed (Permission denied) in d:\devel\www\apache\apache\htdocs\testme.php on line 14

I'd be happy if you could help me with this and/or fix this problem with Windows systems.
Some php ML entry told about this being fixed shortly after 4.0.x, but this might as well have been another issue.

Thanks.
-ae-


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-18 16:59 UTC] sniper@php.net
Try reading the manual sometimes..file != directory.

 [2003-05-18 17:03 UTC] a dot eibach at gmx dot net
Well, Windows seems to be *VERY* sensitive about this.
This thing didn't let me loose, and I just used the Task Manager and killed the 'Explorer' Task - another one was initiated by Windows.
Now it worked!

I will test this through further and append some delays using sleep(). It might be that actions just get executed _too fast_ and Windows can't follow as quickly as Linux.
 [2003-05-18 17:05 UTC] wez@php.net
php.net/rmdir

 [2003-05-18 17:07 UTC] a dot eibach at gmx dot net
to sniper:

actually, this was problems with rename(), not unlink() at first instant in my script.
But since I claim to know that rename() does a copy(), then uses unlink() afterwards, the 'perm. denied' error hadn't to do with rename(), but with unlink().

Yes, rmdir() works now (THANKS!) but I still have problems with unlink()'ing files sometimes.
I admit this script was a very bad example. :|
I tried to keep it simple, but that was too simple...
 [2003-05-18 17:09 UTC] wez@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2003-05-18 17:26 UTC] sniper@php.net
You're just doing somethign wrong, this works fine here.

 [2003-05-18 17:44 UTC] a dot eibach at gmx dot net
YES!

And I just figured it out!

As I said "I wanted to keep it simple".
The whole stuff happened in a 

if ($newdirhandle = @opendir($newdirname))
{
...
}

construct, and *THAT* was causing the problem.
You **must** do a closedir() _BEFORE_ doing this renaming stuff because you're blocking everything otherwise.
Frankly, I thought these two could interact independently of each other, but in fact, they're working closely together.

Anyway, thanks for your reactions.

-ae-
 [2011-09-29 06:03 UTC] saabbir at ovi dot com
Hi all,

That was really helpful. I was having the same problem and i googled a lot for the solution. but couldnt find any handy solution.
After reading this one i got the problem that most of the time we open the file and then try delete the file without even closing (using fclose()) the file. Thats why we get the error that permission was denied.

Thanks for saving my time and server space. lolz

Sabbir
 [2011-09-29 10:09 UTC] a dot eibach at gmx dot net
Hi Sabbir,

I'm very astonished that this would be of help again even EIGHT years later.
I didn't even remember I had ever opened this bug :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 15:01:31 2024 UTC