简体   繁体   English

文件权限-拒绝访问

[英]File Permission - access denied

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(ie 666) and in order to be able to create file in directory "xyz" am checking it for readable and writable mode too(ie 666)... And here is what it prints xyz directory - 777 abc directory - 777 我正在用php制作应用程序,我必须测试某些目录(让我们说“ abc”文件夹)文件权限,并且我必须动态创建一个新文件,让我们在目录“ xyz”中说“文件” ..我想要“ abc”要由网络服务器读取和写入(例如666),并且为了能够在目录“ xyz”中创建文件,还要检查其是否处于可读和可写入模式(例如666)...这就是它打印的xyz目录-777 abc目录-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 $ rootdir包含文件夹“ xyz”的地址...显示以下错误

Message: fopen(C:\\inetpub\\wwwroot\\file.php) [function.fopen]: failed to open stream: Permission denied 消息:fopen(C:\\ inetpub \\ wwwroot \\ file.php)[function.fopen]:无法打开流:权限被拒绝

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? 正如我说的C:\\ inetpub \\ wwwroot文件权限是777 ..最初file.php不存在,但是fopen会创建它..不是吗? And in case it won't, how can i create file dynamically? 万一不会,我该如何动态创建文件?

Any help ? 有什么帮助吗?

$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 参照这个

Windows/NTFS uses an ACL for file permissions. Windows / NTFS使用ACL授予文件权限。

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. 在文件属性对话框的“安全性”选项卡中,您需要授予用户“ Internet来宾帐户([something] / IUSR_ [something])””写访问权限或完全许可权。 You've done this? 你做完了吗?

  • Right click on the file 右键点击文件
  • Click "Properties" 点击“属性”
  • Click the "Security" tab 点击“安全”标签
  • Find the user: "Internet Guest Account" 查找用户:“ Internet访客帐户”
  • Set the necessary permissions 设置必要的权限

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 . 如果希望IIS能够创建文件,则需要确保在文件夹上正确设置了这些ACL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM