RE: [PHP] PHP unlink Permission Error
| From: | Alice Wei | Date: | Tue, 13 Jan 2009 14:50:56 +0000 |
| Subject: | RE: [PHP] PHP unlink Permission Error | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-286215@lists.php.net to get a copy of this message | ||
Hi, Ashley:
I thought about it and edited my script to check what permission I had, and it appears I do have
the permission rights, and it actually changed to 0777. Here is the code:
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
$curDir = getcwd();
chmod($curDir,0777) or die ("Failed to change permission");
echo substr(sprintf('%o', fileperms($curDir)), -4);
unlink("testFile.txt");
echo unlink("testFile.txt");
?>
The output:
0777Warning: unlink(testFile.txt) [function.unlink]: Permission denied in
C:\Inetpub\wwwroot\project\file_write.php on line 10Warning: unlink(testFile..txt)
[function.unlink]: Permission denied in C:\Inetpub\wwwroot\project\file_write.php n line 11If this
is the case, how come I don't have the permissions to delete the file?
Thanks again.
Alice> Subject: Re: [PHP] PHP unlink Permission Error> From: ash@ashleysheridan.co.uk> To:
Alice> ajwei@alumni.iu.edu> CC: php-general@lists.php.net> Date: Tue, 13 Jan 2009 14:53:32 +0000>
Alice> > On Tue, 2009-01-13 at 09:42 -0500, Alice Wei wrote:> > Hi, > > > > I have a
Alice> snippet of code as follows:> > > > <?php> > > >
Alice> ini_set('display_errors', 1); error_reporting(E_ALL);> > $curDir = getcwd();>
Alice> > echo $curDir;> > chmod($curDir,0777);> > unlink("testFile.txt");> >
Alice> echo unlink("testFile.txt"); > > chmod ($curDir,0755);> > ?> > > >
Alice> > The problem is that I do not seem to have the correct permissions, even though I seem to have
Alice> changed the permissions of the folder to 777 already upon the file deletion time. This is the output
Alice> I got:> > > > C:\Inetpub\wwwroot\projectWarning: unlink(testFile.txt) [function.unlink]:
Alice> Permission denied in C:\Inetpub\wwwroot\project\file_write.php on line 9Warning:
Alice> unlink(testFile.txt) [function.unlink]: Permission denied in
Alice> C:\Inetpub\wwwrootproject\file_write.php on line 10> > > > Could anyone give me some
Alice> tips on how to resolve this error? Thanks in advance.> > > > Alice> >
Alice> _________________________________________________________________> > All-in-one security and
Alice> maintenance for your PC. Get a free 90-day trial!> >
Alice> http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail>
Alice> > You're using chmod to modify the permissions of the directory, but do> you actually
Alice> have permissions to modify the permissions? If not, the> chmod will fail without giving an error,
Alice> and then your unlink will fail> with an error.> > > Ash> www.ashleysheridan.co.uk>
Alice>
_________________________________________________________________
Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
http://get.live.com/toolbar/overview