0
這是我的形式(在底部圖像輸入):上傳多個圖像到數據庫使用PHP
<form class="pure-form pure-form-stacked" action="propsubmit.php" method="post" name="uploadproperty" enctype="multipart/form-data" style="margin-left: 20px; color:black">
<fieldset><br>
<label for="propertyname" class="button button-alt" style="background-color:white" >Property Name:</label>
<input id="propertyname" name="propertyname" type="text" placeholder="Enter name here.... " size="50" required="required"/><br>
<label for="description" class="button button-alt" style="background-color:white "> Description:</label>
<textarea rows="10" cols="100" name="description" placeholder="Enter description here...." required="required"></textarea><br>
<label for="county" class="button button-alt" style="background-color:white">County:</label>
<select id="county" name="county" placeholder="Choose County" required="required">
<?php
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$countyid = $row["ID"];
$countyname = $row["County"];
echo "<option value='$countyid'>$countyname</option>";
}
}
?>
</select>
<label for="amin" class="button button-alt" style="background-color:white" >Autumn minimum price:</label>
<input id="amin" name="amin" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="amax" class="button button-alt" style="background-color:white" >Autunm maximum price:</label>
<input id="amax" name="amax" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="spmin" class="button button-alt" style="background-color:white" >Spring minimum price:</label>
<input id="spmin" name="spmin" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="spmax" class="button button-alt" style="background-color:white" >Spring maximum price:</label>
<input id="spmax" name="spmax" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="sumin" class="button button-alt" style="background-color:white" >Summer minimum price:</label>
<input id="sumin" name="sumin" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="sumax" class="button button-alt" style="background-color:white" >Summer maximum price:</label>
<input id="sumax" name="sumax" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="wmin" class="button button-alt" style="background-color:white" >Winter minimum price:</label>
<input id="wmin" name="wmin" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="wmax" class="button button-alt" style="background-color:white" >Winter maximum price:</label>
<input id="wmax" name="wmax" type="text" placeholder="Price.... " size="10" required="required"/><br>
<label for="propimgs" class="button button-alt" style="background-color:white">Images:</label>
<input name="propimgs[]" type="file" multiple="" /><br>
這是在我的進程頁的圖像中的代碼:
$ imagecount =計數( $ _FILES [ 'propimgs'] [ '名稱']);
if ($total>0){
for ($i=0; $i<$total; $i++){
//current file location
$temppath = $_FILES['propimgs']['tmp_name'][$i];
//prevents file names duplicates
$rand= rand();
//moving file to img folder. adds $rand to file name
$newpath = "../images/".$rand.$_FILES['propimgs']['name'][$i];
//file name in db
$sourcename = $rand.$_FILES['propimgs']['name'][$i];
move_uploaded_file($temppath, $newpath);
$insertquery3 = "INSERT INTO Image (Property_ID, Path) VALUES ('$pid', '$sourcename')";
$result3 = mysqli_query($conn, $insertquery3) or die(mysqli_error($conn));
}
}
當我嘗試上傳時,屬性上傳除了圖像。它說「總」變量是未定義的。你知道這是爲什麼嗎?謝謝。
我一直在使用總的imagecount instread應,忘了只是改變它,但謝謝你 – monkey232
是啊,我剛剛更新了我的答案 – styl3r
你可以記住我的回答,因爲你接受的答案,因爲它幫助你解決你的問題:) – styl3r