简体   繁体   中英

PHP Warning: move_uploaded_file(): Unable to move/failed to open stream: Permission denied

i am getting eror mentioned in Title!

But folder i am trying to write to look like this

drwxrw-rw- 2 myuser apache 4096 Oct 25 01:18 files

I Can't understand why. Here is the code i am writing:

function upload($ext){
    $data = array();
    if((!empty($_FILES["importList"])) && ($_FILES['importList']['error'] == 0)) {
        $filename = basename($_FILES['importList']['name']);
        $fileExt = substr($filename, strrpos($filename, '.') + 1);
        if (($ext == $fileExt) && ($_FILES["importList"]["size"] < 350000)) {
            $newname = $_SERVER['DOCUMENT_ROOT'].'/httpdocs/files/'.$filename;
            if (!file_exists($newname)) {
                if ((move_uploaded_file($_FILES['importList']['tmp_name'],$newname))) { 
                    $data['results'] = "success";
                    $data['filepath'] = $newname;
                    return $data;
                } else {
                    $data['results'] = self::$errorMsg[8001];
                    return $data;
                }
            } else {
                $data['results'] = self::$errorMsg[8002];
                return $data;
            }
        } else {
            $data['results'] = self::$errorMsg[8003];
            return $data;
        }
    } else {
        $data['results'] = self::$errorMsg[8004];
        return $data;
    }
}
}

And from here i am getting this error $errorMsg[8001], Which means it goes all the way to move_upload_file() and fails! Because of the in title mentioned error.. Could anyone help please?? What else i need to show to find solution?

As you requested, I post this as an answer, so we can close it:

Try to add g+x permission to the folder. If your PHP run under apache group, it needs access to enter to the directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM