Insert code :
<form method = "POST" action = "add_visual.php" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputFile">Image input</label>
<input type="file" name = "files[]" multiple>
<button type="submit" name = "upload" class="btn btn- default">Upload</button>
</div>
Display code :
$count = 0; // to add <div class="row"> after every 4 image display
$sql = "SELECT img_name, address FROM visual ORDER BY visual_id DESC";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result))
{
echo '<div class="col-lg-3 col-md-4 col-xs-6 thumb">';
echo '<a class="thumbnail" href="#">';
echo '<img class="img-responsive" src="' .$row["address"] . $row["img_name"] . '" alt="">';
echo '</a>';
echo '</div>';
$count++;
if($count % 4 == 0)
{
echo '</div>';
echo '<div class="row">';
}
}
}
else {
echo "0 results";
}
mysqli_close($conn);
This is how it handles one photo, any way of doing multiple images ? Here is the php process of how the data is input into the form.
<?php
include 'dbconnect.php';
if(isset($_POST["files"]))
{
/*
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$folder="images/";
move_uploaded_file($file_loc,$folder.$file);
$sql="INSERT INTO visual(img_name, address) VALUES('$file', '$folder')";
mysqli_query($conn,$sql);
*/
extract($_POST);
$error=array();
$extension=array("jpeg","jpg","png","gif");
foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name)
{
$file_name=$_FILES["files"]["name"][$key];
$file_tmp=$_FILES["files"]["tmp_name"][$key];
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
{
if(!file_exists("photo_gallery/".$txtGalleryName."/".$file_name))
{
move_uploaded_file($file_tmp=$_FILES["files"] ["tmp_name"][$key],"images/".$file_name);
}
/*
else
{
$filename=basename($file_name,$ext);
$newFileName=$filename.time().".".$ext;
move_uploaded_file($file_tmp=$_FILES["files"] ["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$newFileName);
}
*/
}
else
{
array_push($error,"$file_name, ");
}
}
}
?>
Any help on this will be appreciated. I'm kinda lost on how to make multi upload, what am I missing out. Thank you.