无法打开流权限被拒绝

时间:2013-03-20 03:21:59

标签: php html image

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

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

在loggedin.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,它必须是代码,但为什么呢?

由于

1 个答案:

答案 0 :(得分:5)

该文件夹有哪些权限?您可能需要更改它以使PHP能够写入它。