PHP write outside document root

人盡茶涼 提交于 2019-12-20 04:33:07

问题


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";
?>

回答1:


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.




回答2:


It sounds like safe mode is on and doc_root has been set. You'll need to set doc_root to empty or turn off safe mode.



来源:https://stackoverflow.com/questions/3313779/php-write-outside-document-root

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!