0
在這裏,我的php腳本在服務器上傳圖片。我希望用戶可以在一個記錄上上傳多個圖像。現在,在這段代碼中,只有一個圖像可以發佈,用戶的要求是他們可以發佈多個圖像。我不知道如何才能使用數組。請幫忙。感謝提前:)如何使用PHP表單一次性ulpload多個圖像?
<?php
include ("connect.php");
if(isset($_POST['submit']))
{
$event = $_POST['evnt_name'];
$image_name = $_FILES['evnt_img']['name'];
$image_type = $_FILES['evnt_img']['type'];
$image_size = $_FILES['evnt_img']['size'];
$image_tmp = $_FILES['evnt_img']['tmp_name'];
if($event=='' && $image_name==''){
echo "<script>alert('Any field is empty')</script>";
exit();
}
if($image_type=="image/jpeg" OR $image_type=="image/png" OR $image_type=="image/gif")
{
if($image_size<=50000)
{
move_uploaded_file($image_tmp,"imagess/$image_name");
}
else
{
echo "<script>alert('image is large, only 50kb size allowed')</script>";
exit();
}
}
else{
echo "<script>alert('image type is invalid')</script>";
exit();
}
$query = "insert into event_update (evnt_text,evnt_img) values ('$event','$image_name')";
if(mysqli_query($conn,$query))
{
echo "<script>alert('Post has been published')</script>";
exit();
}
}
?>
及以下形式
<div class="col-lg-12">
<form method="POST" action="evntform.php" enctype="multipart/form-data">
<div class="form-group">
<label>Events Name</label>
<input type="text" name="evnt_name" placeholder="Write Events Name" class="form-control">
</div>
<div class="form-group">
<label>File input</label>
<input type="file" name="evnt_img[]">
</div>
<button name="submit" type="submit" class="btn btn-default">Submit Button</button>
</form>
</div>
好,好..我新受告訴我怎樣才能在使用「迴路」以上代碼.. plz –
上面的for循環計數從0到您陣列中的文件數量:請參閱:https://www.w3schools.com/php/php_looping_for.asp 在您編程時學習! –
好,但現在問題是前端..在形式用戶如何可以選擇多個圖像..只有一個圖像可選。 –