PHP写外部文件根 [英] PHP write outside document root
问题描述
我正在尝试在Web服务器文档根目录之外的目录中创建文件.该文件夹的权限为777,但php表示权限被拒绝: 警告:fopen(/home/site2/public_html/images/x.jpg)[function.fopen]:无法打开流:在第2行的/home/site1/public_html/test_sites.php中,权限被拒绝 权限问题
I'm trying to create a file in a directory outside the document root of the web server. The folder has permissions 777 but php says Permission Denied: Warning: fopen(/home/site2/public_html/images/x.jpg) [function.fopen]: failed to open stream: Permission denied in /home/site1/public_html/test_sites.php on line 2 Permission problem
<?php
$f = fopen('/home/site2/public_html/images/x.jpg', 'wb');
if(!$f) die("Permission problem");
fclose($f);
echo "OK";
?>
推荐答案
777权限是成功的一半.您还需要使用以下命令将组更改为www-data(如果在debian上):
The 777 permissions is half the battle. You will also need to change the group to be www-data (if on debian) using the:
chgrp g+w www-data /home/growtent/public_html/images
根据您正在运行的系统以及我的记忆正确,该应"工作.
That "should" work, depending on what system you are running and given that my memory is correct.
这篇关于PHP写外部文件根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!