windows 由 PHP move_uploaded_file() 修改的文件的奇数权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/205822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Odd permissions on file modified by PHP move_uploaded_file()
提问by user13414
I'm running PHP 5.2.6 on a Windows Server 2003 Enterprise box. IIS is set to deny anonymous access and use Integrated Windows authentication.
我在 Windows Server 2003 Enterprise 机器上运行 PHP 5.2.6。IIS 设置为拒绝匿名访问并使用集成 Windows 身份验证。
I'm using a PHP script to save a file uploaded from a web form. The file is uploaded to a temp folder, the script creates a file name and path depending on other variables from the web form, and then the script uses PHP's move_uploaded_file() to move the temp file to the final location. All that works fine. In short, people are uploading files so everyone in the group can see them and the files are organized by the script.
我正在使用 PHP 脚本来保存从 Web 表单上传的文件。文件上传到临时文件夹,脚本根据网络表单中的其他变量创建文件名和路径,然后脚本使用 PHP 的 move_uploaded_file() 将临时文件移动到最终位置。一切正常。简而言之,人们正在上传文件,以便组中的每个人都可以看到它们,并且文件由脚本组织。
My problem is that the file in the final location has odd permissions. It is not ending up with permissions from either the temp location or the final location. Both the temp location and final location have the same permissions: full rights for owner and administrations; read and read/execute for 2 specific AD security groups. The final file ends up with only: full rights for owner and administrations. So while the admins and the original uploader have no problem viewing the file, all others in the group get "permission denied" when trying to access it.
我的问题是最终位置的文件具有奇怪的权限。它不会以来自临时位置或最终位置的权限结束。临时位置和最终位置具有相同的权限:所有者和管理人员的完全权限;读取和读取/执行 2 个特定的 AD 安全组。最终文件最终只有:所有者和管理人员的完全权利。因此,虽然管理员和原始上传者在查看文件时没有问题,但组中的所有其他人在尝试访问文件时都会收到“权限被拒绝”。
Any ideas or suggestions will be greatly appreciated! Thanks!
任何想法或建议将不胜感激!谢谢!
采纳答案by Chris Roland
This seems to be an issue with the move_uploaded_file()
function:
http://us3.php.net/move_uploaded_file
Take a look at the comments below, take note of Florian's comment about copy().
Would copy() solve the issue?:
http://us3.php.net/manual/en/function.copy.php
这似乎是move_uploaded_file()
函数的问题:
httpmove_uploaded_file
: //us3.php.net/
看看下面的评论,注意 Florian 关于 copy() 的评论。
copy() 会解决问题吗?:http:
//us3.php.net/manual/en/function.copy.php
回答by user13414
from the php page on move_uploaded_file (nb: this worked for me):
来自 move_uploaded_file 上的 php 页面(注意:这对我有用):
For those using PHP on Windows and IIS, you SHOULD set the "upload_tmp_dir" value in php.ini to some directory around where your websites directory is, create that directory, and then set the same permissions on it that you have set for your websites directory. Otherwise, when you upload a file and it goes into C:\WINDOWS\Temp, then you move it to your website directory, its permissions will NOT be set correctly. This will cause you problems if you then want to manipulate that file with something like ImageMagick's convert utility.
对于那些在 Windows 和 IIS 上使用 PHP 的人,您应该将 php.ini 中的“upload_tmp_dir”值设置为您网站目录所在的某个目录,创建该目录,然后在其上设置您为网站设置的相同权限目录。否则,当您上传文件并进入 C:\WINDOWS\Temp,然后将其移动到您的网站目录时,将无法正确设置其权限。如果您想使用 ImageMagick 的转换实用程序之类的工具操作该文件,这会给您带来问题。