【发布时间】:2013-11-27 21:25:16
【问题描述】:
我正在创建个人资料图片上传器,用户可以在其中选择文件并上传,但出现此错误:
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,它一定是代码,但是为什么呢?
谢谢
【问题讨论】:
-
它告诉你出了什么问题。您没有移动文件的权限。您需要修复您的文件系统/用户权限,这完全在您发布的代码之外。
-
确保您尝试将图像移动到的文件夹可由 php 写入
-
好的,我在 mac 上,我该怎么做?我在考虑让它可读可写?
-
好的,这有效,但现在我没有得到地址的回声?
-
@meagar 我该怎么办?