2

我正在创建一个个人资料图片上传器,用户可以在其中选择一个文件并上传它,但我收到此错误:

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

第二到第五行是:

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);
}

login.php 文件中的其余部分是:

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">';
        }

我不确定我做错了什么?它不是我的.htaccess,它必须是代码,但为什么呢?

谢谢

4

1 回答 1

6

文件夹的权限是什么?您可能需要更改它以使 PHP 能够对其进行写入。

于 2013-03-20T03:24:43.133 回答