警告:move_uploaded_file();未能打开流
问题描述:
我试图使用move_uploaded_file();
警告:move_uploaded_file();未能打开流
$target_dir = "product_images/";
$target_file = $target_dir . basename($_FILES["product_image"]["name"]);
if (move_uploaded_file($_FILES["product_image"]["tmp_name"], $target_file)) { // Line 92
echo "<script>alert('The file " . basename($_FILES["product_image"]["name"]) . " has been uploaded.')</script>";
} else {
echo "<script>alert('Sorry, there was an error uploading your file.')</script>";
die();
}
所以要上传图片时,我尝试执行此代码我得到这个错误:
Warning: move_uploaded_file(product_images/img_forest.jpg): failed to open stream: Permission denied in /opt/lampp/htdocs/suvenirshop/admin_area/insert_product.php on line 92
Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpZEJdEV' to 'product_images/img_forest.jpg' in /opt/lampp/htdocs/suvenirshop/admin_area/insert_product.php on line 92
我使用XAMPP Linux的,我也试过这个代码在Windows PC和MAC,我得到相同的错误。 我不得不提,我有文件夹product_images在我存储insert_product.php执行此代码的文件夹中。
答
尝试为product_images文件夹提供写入权限。在终端后藤在Linux系统中product_images文件夹中cd
命令创建的文件夹,然后chmod a+w product_images
命令
'权限denied'检查权限的'product_images'你工作,我改变了对文件夹的权限对所有要读写 –
谢谢现在它可以工作 –