我有一個本地安裝(PHP4/MySQL)設計的應用程序,它的工作原理非常完美。因爲我把它移動到一個實時安裝(PHP5/MySQL),我什麼都沒有,但問題!我修正了所有全局變量問題(導致我學習PDO,所以不是一件壞事!),而不用開啓全局變量,所以我唯一的問題就是文件上傳。我試過$ _file的isset測試,它看起來像變量從未設置?有任何想法嗎?文件上傳在PHP4上,但不是PHP5
這裏是表單數據:
<form enctype="multipart/form-data" method="post" action="script_add_product.php" >
<input class="cp_forms_upload" type="file" name="full_image" />
<input class="cp_formsButton" type="submit" name="submit_button" value="Add Product" /></form>
這裏是PHP:
$full_image_url = $_FILES["full_image"]["name"];
if ((($_FILES["full_image"]["type"] == "image/gif")
|| ($_FILES["full_image"]["type"] == "image/jpeg")
|| ($_FILES["full_image"]["type"] == "image/pjpeg")
|| ($_FILES["full_image"]["type"] == "image/png"))
&& ($_FILES["full_image"]["size"] < 400000))
{
if ($_FILES["full_image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["full_image"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["full_image"]["name"] . "<br />";
echo "Type: " . $_FILES["full_image"]["type"] . "<br />";
echo "Size: " . ($_FILES["full_image"]["size"]/1024) . " Kb<br />";
echo "Temp file: " . $_FILES["full_image"]["tmp_name"] . "<br />";
if (file_exists("../Uploads/" . $_FILES["full_image"]["name"]))
{
echo $_FILES["full_image"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["full_image"]["tmp_name"],
"../Uploads/" . $_FILES["full_image"]["name"]);
echo "Stored in: " . "../Uploads/" . $_FILES["full_image"]["name"];
echo "<br /><br /><br />" . $full_image_url;
}
}
}
else
{
echo "Invalid file";
}
感謝鄉親:)
是什麼$ _ POST輸出的var_dump($ _ POST); – Bono 2012-07-28 19:55:10
你確定你想上傳圖片不大於upload_max_filesize值越大 – mrok 2012-07-28 20:01:35
mrok,我?已經測試了大小隻有20kb的圖片Upload_max_filesize是16M Bono,我怎麼var_dump? – 2012-07-28 21:10:57