Multiple image upload to Database. Without using Ajax and Jquery . Just select multiple images direct upload on database. file store array implode method and fetch multiple in explode concept, follow this notes learn how to upload multiple images in database.
multiple image
Database
CREATE TABLE `image`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` varchar(250) NOT NULL,
)
HTML
<html>
<head>
<meta charset="UTF-8" />
<title>Multiple File Ppload with PHP</title>
</head>
<body>
<div align="center" style="width:700px; border:dashed 2px #0099FF;">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file" name="support_images[]" multiple accept="image/*" />
<input type="submit" name="sub" value="Upload!" />
</form>
</div>
<?php
$view=mysql_query("select * from image");
while($row=mysql_fetch_array($view))
{
$path=explode("*",$row['image']);
$i=count($path);
$file_path = 'uploads/';
for($j=0;$j<$i;$j++)
{
$src=$file_path.$path[$j];
?>
<div style="width:250px; float:left; height:150px; margin-top:20px; border:dashed 2px #0099FF;">
<img src="<?php echo $src; ?>" width="240" height="140">
</div>
<?php } } ?>
</body>
</html>
PHP
<?php
if(isset($_POST['sub']))
{
extract($_POST);
if(isset($_FILES['support_images']['name']))
{
$file_name_all="";
for($i=0; $i<count($_FILES['support_images']['name']); $i++)
{
$tmpFilePath = $_FILES['support_images']['tmp_name'][$i];
if ($tmpFilePath != "")
{
$path = "uploads/"; // create folder
$name = $_FILES['support_images']['name'][$i];
$size = $_FILES['support_images']['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['support_images']['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, '*');
}
else
{
$filepath="";
}
$query=mysql_query("INSERT into image (`image`) VALUES('".addslashes($filepath)."'); ");
if($query)
{
header("location:".$_SERVER['PHP_SELF']);
}
}
?>
Note : Upload below 800kb files
multiple image
Database
CREATE TABLE `image`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` varchar(250) NOT NULL,
)
HTML
<html>
<head>
<meta charset="UTF-8" />
<title>Multiple File Ppload with PHP</title>
</head>
<body>
<div align="center" style="width:700px; border:dashed 2px #0099FF;">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file" name="support_images[]" multiple accept="image/*" />
<input type="submit" name="sub" value="Upload!" />
</form>
</div>
<?php
$view=mysql_query("select * from image");
while($row=mysql_fetch_array($view))
{
$path=explode("*",$row['image']);
$i=count($path);
$file_path = 'uploads/';
for($j=0;$j<$i;$j++)
{
$src=$file_path.$path[$j];
?>
<div style="width:250px; float:left; height:150px; margin-top:20px; border:dashed 2px #0099FF;">
<img src="<?php echo $src; ?>" width="240" height="140">
</div>
<?php } } ?>
</body>
</html>
PHP
<?php
if(isset($_POST['sub']))
{
extract($_POST);
if(isset($_FILES['support_images']['name']))
{
$file_name_all="";
for($i=0; $i<count($_FILES['support_images']['name']); $i++)
{
$tmpFilePath = $_FILES['support_images']['tmp_name'][$i];
if ($tmpFilePath != "")
{
$path = "uploads/"; // create folder
$name = $_FILES['support_images']['name'][$i];
$size = $_FILES['support_images']['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['support_images']['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, '*');
}
else
{
$filepath="";
}
$query=mysql_query("INSERT into image (`image`) VALUES('".addslashes($filepath)."'); ");
if($query)
{
header("location:".$_SERVER['PHP_SELF']);
}
}
?>
Note : Upload below 800kb files
0 comments:
Post a Comment