我試過一些代碼來保存我上傳的圖像在文件夾中。文件夾的路徑是C:\xampp\htdocs\gripOffers\Store_Brand\store_admin\images
。我無法將其保存在文件夾中。這個怎麼做?我在哪裏做錯了?已上傳的圖像移動到文件夾 - php
代碼
if(isset($_POST['submit'])) {
$image = $_FILES['file']['name'];
$temp_name = $_FILES["file"]["tmp_name"];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$type = pathinfo($image, PATHINFO_EXTENSION);
echo "<br>";
echo $type;
echo "<br>";
if ((($type == "image/gif")
|| ($type == "jpeg")
|| ($type == "jpg")
|| ($type == "pjpeg")
|| ($type == "x-png")
|| ($type == "png"))
&& ($_FILES["file"]["size"] < 50000)
) {
$m = move_uploaded_file($_FILES["file"]["tmp_name"], "/Store_Brand/store_admin/images/" . $image);
if ($m) {
echo "uploaded!";
} else {
echo "no";
}
} else {
echo "file type is not image";
}
}
嘗試添加'DOCUMENT_ROOT'到目標路徑。 –
@u_mulder在哪一行? – tabia
@tabia,'move_uploaded_file' - 那一個。檢查該目錄的權限也無妨。 – Pyromonk