Solution Call to a member function move() to null

Solution Call to a member function move() to null

    PHP File Upload Problem. PHP may give you two types of error

    Call to a member function move() to null

    or

    PHP - mkdir(): Permission denied

    If you see the above error, that means you are having problem creating a directory. Since your server apache or nginx does not have the permission to create a directory, the move() function can not create and move a file.

    In general the permission issue happens if you change server or upload your project to a completely new server. 

    There are a few ways to grant your apache or nginx server to create file permission. Here's how I did it.

    sudo chown -R www-data /folder

    Here www-data for Ubunto 

    sudo chown -R apache /folder

    for Linux server

    -R means recursively. So in general if you want to create a file inside uploads folder, then it would like below

    sudo chown -R www-data /var/www/html/example.com/public/uploads

    sudo chown -R apache /var/www/html/example.com/public/uploads

    Folder path could be anyone for you.

    There's another approach that could work as well

    Last approach for changing the file creating permission is to let SELinux do it for you. But you need to assign permission to it.

    chcon -R -t httpd_sys_content_t /path/to/www
    chcon -R -t httpd_sys_content_rw_t /path/to/www/dir/for/rw

    Courses


    Recommended posts


    Recent posts