我看到的大多數問題都是使用一個圖像輸入。但是如果你有2個或3個或更多?一個表單中的多個圖像輸入?
我的腳本爲一個圖像輸入工作,但我想在我的窗體中有一個單一圖像輸入和一個多個圖像輸入。我正在測試我的表單上有2個單一圖像輸入,但無法工作。
下面是一個單圖像輸入(假設它是一個<形式>標記內)的HTML:
<input type="hidden" name="size" value="350000"/>
<input type="file" name="schoollogo"/><br/>
的PHP:
$target = "images/logo/";
$target = $target . basename($_FILES['schoollogo']['name']);
$schoollogo = $_FILES['schoollogo']['name'];
//Writes the information to the database
mysql_query("INSERT INTO Colleges (schoollogo) VALUES ('$schoollogo')") or die(mysql_error()) ;
//Writes the logo to the server
if (move_uploaded_file($_FILES['schoollogo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
對於第二單圖像輸入,我剛剛添加了第二個輸入代碼...
<input type="hidden" name="size" value="350000"/>
<input type="file" name="otherimage"/><br/>
然後將該變量添加到PHP:
$targetotherimage = "images/otherimage/";
$targetotherimage = $targetotherimage . basename($_FILES['otherimage']['name']);
mysql_query("INSERT INTO Colleges (schoollogo,otherimage) VALUES ('$schoollogo','$otherimage')") or die(mysql_error()) ;
//Writes the logo to the server
if (move_uploaded_file($_FILES['schoollogo']['tmp_name'], $target)) && (move_uploaded_file($_FILES['otherimage']['tmp_name'], $targetotherimage)) {
但是,當將該代碼添加到PHP中時,代碼不起作用。沒有錯誤信息或任何東西。該頁面爲空白。
順便說一句,here is my other question在那裏我試圖添加一個多圖像上傳輸入到我的表單與一個已經工作的單圖上傳輸入。
可能的重複[參考 - 這個錯誤在PHP中意味着什麼? - 什麼都看不到。該頁面是空白的。](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851) – CBroe