简体   繁体   中英

Failed to open stream permission denied

I am creating a profile image uploader, where the user can select a file and upload it, but I am getting this error:

Warning: move_uploaded_file(user_files/profile_img/c3487ff77d.jpg) [function.move-    uploaded-file]: failed to open stream: Permission denied in     /Applications/XAMPP/xamppfiles/htdocs/projects/lr/core/functions/users.php on line 4

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpi0WECJ' to 'user_files/profile_img/c3487ff77d.jpg' in /Applications/XAMPP/xamppfiles/htdocs/projects/lr/core/functions/users.php on line 4

Line two through five is:

function change_profile_image($user_id, $file_temp, $file_extn) {
$file_path = 'user_files/profile_img/' . substr(md5(time()), 0, 10) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
}

And the rest in a loggedin.php file is:

if (isset($_FILES['profile_img']) === true) {
            if (empty($_FILES['profile_img']['name']) === true) {
                echo 'Please choose a file!';
            } else {
                $allowed = array('jpg', 'jpeg', 'png');

                $file_name = $_FILES['profile_img']['name'];
                $file_extn = strtolower(end(explode('.', $file_name)));
                $file_temp = $_FILES['profile_img']['tmp_name'];

                if (in_array($file_extn, $allowed) === true) {
                    change_profile_image($session_user_id, $file_temp, $file_extn);
                } else {
                    echo 'Invalid file type! Allowed Types: ';
                    echo implode(', ', $allowed);
                }
            }
        }

        if (empty($user_data['profile_img']) === false) {
            echo '<img src="', $user_data['profile_img'],'" alt="', $user_data['first_name'] ,'\'s Profile Image">';
        }

I'm not sure what I am doing wrong? Its not my .htaccess, it must be the code, but why?

Thanks

What are the permissions on the folder? You may need to change it to enable PHP to write to it.

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