Reputation: 283
I am making an application in php and i have to test certain directories(lets say "abc" folder) file permissions and i have to create a new file dynamically ,lets say "file" in directory "xyz" .. I want "abc" to be readable and writable by webserver(i.e. 666) and in order to be able to create file in directory "xyz" am checking it for readable and writable mode too(i.e. 666)... And here is what it prints xyz directory - 777 abc directory - 777
But when i try to
$data = 'Some file data';
$fh = fopen($rootdir."\\file.php","r+");
if ( !fwrite($fh,$data))
{
//echo $rootdir;
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
fclose($fh);
$rootdir contain address of folder "xyz" ... It shows following error
Message: fopen(C:\inetpub\wwwroot\file.php) [function.fopen]: failed to open stream: Permission denied
As i said C:\inetpub\wwwroot file permissions are 777.. And initially file.php don't exist but fopen will create it.. isn't it? And in case it won't, how can i create file dynamically?
Any help ?
Upvotes: 1
Views: 4778
Reputation: 28775
$fh = fopen($rootdir."\\file.php","r+");;
will not create the file if it doesn't exist. To create file you need to use
$fh = fopen($rootdir."\\file.php","w");
Or
$fh = fopen($rootdir."\\file.php","w+");
Refer to this this
Upvotes: 1
Reputation: 6773
Windows/NTFS uses an ACL for file permissions.
In the file property dialog box "security" tab, you need to give the user "Internet Guest Account ([something]/IUSR_[something])" write access, or full permission. You've done this?
If you want to IIS to be able to create files, you need to make sure you have these ACLs set up correctly on the folder.
Upvotes: 0