首页 文章

PHP:“未能打开流:权限被拒绝”

提问于
浏览
2

当我尝试通过某个Function访问任何目录或文件时,我在服务器上得到了一些有趣的结果 . 我已将所有文件和目录权限设置为777并将内容所有者更改为Apache但我仍然收到错误消息 . 代码:
move_uploaded_file($_FILES['file']['tmp_name'], '/var/www/html/fileContent_Site/userData/'.$_SESSION['username'].DIRECTORY_SEPARATOR.$_FILES['file']['name']);
file_put_contents('userData/userData.txt', $result,FILE_APPEND); mkdir("userData/".$register['username']);

对于'move_uploaded_file()',我得到:

move_uploaded_file(/var/www/php/Site/userData/radi/110729.png):无法打开流:/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()'

file_put_contents(userData / userData.txt):无法打开流:/var/www/php/Site/register.php中的权限被拒绝mkdir():/var/www/php/Site/register.php中的权限被拒绝

2 回答

  • 0

    使用

    $_SERVER["DOCUMENT_ROOT"]."/myFolder/path to upload folder".
    

    并检查一次

  • 0

    打开http.conf(在/opt/lampp/etc/httpd.conf)文件中 .

    编辑此部分:

    <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>
    

    看,如果有效 .

相关问题