Tuesday, 24 June 2014

how to upload multiple images in php mysql

<?php
if($_FILES['Enginimage']['name'])
{
 foreach ($_FILES['Enginimage']['name'] as $name => $value)
    {
$source=$_FILES['Enginimage']['tmp_name'][$name];
   $target='uploads/'.time().stripslashes($_FILES['Enginimage']['name'][$name]);
$image_name= 'Engin#'.time().stripslashes($_FILES['Enginimage']['name'][$name]);
if (copy($source,$target))
           {
      $time=time();
  $carid=session_id();
 $queryimage="INSERT INTO photo(carId,image_name,modified_date) VALUES('$carid','$image_name','$time')";
      mysql_query("$queryimage");
  }
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form method="post" id="EnginImage"  class="form-horizontal" enctype="multipart/form-data">
              <input type="file" name="Enginimage[]" multiple="true"/>
             <input type="submit" id="submited" name="submited" value="Image Upload"  />
            </form>
</body>
</html>

1 comment :