PHP:“无法打开流:权限被拒绝"; [英] PHP: "failed to open stream: Permission denied"
问题描述
当我尝试通过某些功能访问任何目录或文件时,我在服务器上得到了一些有趣的结果.我已经设置了所有文件&目录权限为777,并将内容所有者更改为Apache,但我仍然收到错误消息.代码: move_uploaded_file($ _ FILES ['file'] ['tmp_name'],'/var/www/html/fileContent_Site/userData/'.$_ SESSION ['username'].DIRECTORY_SEPARATOR.$ _ FILES ['file'] ['名称']);
或者 file_put_contents('userData/userData.txt',$ result,FILE_APPEND);
mkdir("userData/".$ register ['username']);
I am getting some interesting results on my server when i try to access any Directory or File via some Function.I have set all my file & directory permissions to 777 and have changed the content owner to Apache but i still get error messages.Code:
move_uploaded_file($_FILES['file']['tmp_name'], '/var/www/html/fileContent_Site/userData/'.$_SESSION['username'].DIRECTORY_SEPARATOR.$_FILES['file']['name']);
Or
file_put_contents('userData/userData.txt', $result,FILE_APPEND);
mkdir("userData/".$register['username']);
对于"move_uploaded_file()",我得到:
For 'move_uploaded_file()' i get:
move_uploaded_file(/var/www/php/Site/userData/radi/110729.png):无法打开流:/var/www/php/Site/upload.php中的权限被拒绝
move_uploaded_file(/var/www/php/Site/userData/radi/110729.png):failed to open stream: Permission denied in /var/www/php/Site/upload.php
move_uploaded_file():无法将/var/www/php/Site/upload.php中的'/tmp/phpUFvMcn'移至'/var/www/php/Site/userData/radi/110729.png'>
对于'file_put_content()'和'mkdir()'
And for 'file_put_content()' and 'mkdir()'
file_put_contents(userData/userData.txt):无法打开流:/var/www/php/Site/register.php中的权限被拒绝
file_put_contents(userData/userData.txt): failed to open stream: Permission denied in /var/www/php/Site/register.php
mkdir():/var/www/php/Site/register.php中的权限被拒绝
mkdir(): Permission denied in /var/www/php/Site/register.php
推荐答案
打开http.conf(在/opt/lampp/etc/httpd.conf中)文件.
Open http.conf (in /opt/lampp/etc/httpd.conf) file.
编辑此部分:
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User hostname
Group hostname
</IfModule>
看,如果可行.
这篇关于PHP:“无法打开流:权限被拒绝";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!