php - 使用 PHP 在 Windows 中设置文件权限

标签 php windows file permissions

我有一个脚本上传 *.csv 以导入到我拥有的数据库表中,它在 linux 中通过 chmod($target, 0777); 运行良好,但我不能我的生活找到了解决方案来做到这一点,但在基于 Windows 的 Apache 服务器上。

其他一些帖子有人回应“不要放入 0777,它应该可以工作”,但我不是这样。谢谢!

最佳答案

多亏了我原来帖子上留下的评论,我才能够在 https://web.archive.org/web/20171121192635/http://www.howyoudo.info/index.php/how-to-fix-windows-server-upload-file-inherit-permissions-error/ 的更多帮助下弄明白。

The problem only happens when you use PHP to upload a file. When you upload a file, PHP sends the file to a temporary directory on the hard drive (for me it is C:\Windows\Temp) and then copies it over to it’s intended directory. Once the file has landed in the temporary directory, it is assigned the permissions of that directory. The problem is when Windows copies that file, it keeps the temporary directory’s permissions and doesn’t inherit your web directory’s permissions.

The easiest way to fix this problem is to add to the temporary directory your intended web directory’s permissions. There’s no need to erase the permissions already in the temporary directory, just add the web directory’s permissions to them. In other words, follow these steps

  1. To change the permissions of your temporary upload directory, find the “upload_tmp_dir” in your php.ini file.
  2. Set it to the directory of your choosing (outside your web folders of course) or leave it at default (for me it is C:\Windows\Temp).
  3. Browse to this folder and add the permissions of your web folders to it.

关于php - 使用 PHP 在 Windows 中设置文件权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23851821/

相关文章:

PHP - 调查来自供应商的 HTTP 内容

php - Wordpress wp_update_user 仅在刷新后更新

php - 始终从行中获取最后一个值

python - 如何使用线程或其他一些快速方式获取网站?

windows - 从网站启动可执行文件?

Windows 8.1 关机批处理

c# - "file"不包含 'Delete' 的定义

java - android java.io.File.fixSlashes(File.java :185)

php - 如果使用 php/mysqli 值为空,如何将列值设置为零?

Emacs 打开最近的文件很慢!