In this blog post we focused on Multiple Image uploading functionality using PHP.
Here, We have given complete Multiple Image Uploading Script.
HTML Code :-
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file" name="imgs[]" multiple="multiple" accept="image/*" />
<input type="submit" name="upload" value="Upload!" />
</form>
Insert Code-:
<?phpif(isset($_POST['upload'])) { extract($_POST); if(isset($_FILES['imgs']['name'])) { $file_name_all=""; for($i=0; $i<count($_FILES['imgs']['name']); $i++) { $tmpFilePath = $_FILES['imgs']['tmp_name'][$i]; if ($tmpFilePath != "") { $path = "uploads/"; $name = $_FILES['imgs']['name'][$i]; $size = $_FILES['imgs']['size'][$i]; list($txt, $ext) = explode(".", $name); $file= time().substr(str_replace(" ", "_", $txt), 0); $info = pathinfo($file); $filename = $file.".".$ext; if(move_uploaded_file($_FILES['imgs']['tmp_name'][$i], $path.$filename)) { date_default_timezone_set ("Asia/Calcutta"); $currentdate=date("d M Y"); $file_name_all.=$filename."*"; } } } $filepath = rtrim($file_name_all, '*'); //imagepath if it is present } else { $filepath=""; } $query=mysql_query("INSERT into image (`image`) VALUES('".addslashes($filepath)."'); "); if($query) { header("location:".$_SERVER['PHP_SELF']); }}?>
Here Display upload Images Code :-
<?php
$insert_sql=$db->query("select * from image");
while($upload_img=$insert_sql->fetch_array())
{
$img_path=explode("*",$upload_img['image']);
$i=count($img_path);
$file_path = 'uploads/';
for($j=0;$j<$i;$j++)
{
$src=$file_path.$img_path[$j];
?>
<img src="<?php echo $src; ?>" width="240" height="140">
<?php
}
}
?>
Sign up here with your email