0
我試圖使用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執行此代碼的文件夾中。
'權限denied'檢查權限的'product_images'你工作,我改變了對文件夾的權限對所有要讀寫 –
謝謝現在它可以工作 –