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