Upload multiple file upload in php
HTML CODE:
VIEW YOUR UPLOADED IMAGES:
Multiple file upload
Multiple file upload
PHP SCRIPT :
<?php
if (isset($_POST['submit']))
{
$myFile = $_FILES['my_file'];
$fileCount = count($myFile["name"]);
$image_array=array();
for ($i = 0; $i < $fileCount; $i++)
{
//target directory for image save
$target_dir = "uploaded_images/";
//remove spaces from the filename
$fname = trim(preg_replace('/\s+/', '-', $myFile["name"][$i]));
//filename changed with time function
$target_file = $target_dir . time() . $fname;
//fetching host and current url
$abc = $_SERVER['HTTP_HOST'].''.$_SERVER['REQUEST_URI'];
$a = explode( "/" , $abc );
array_pop($a);
$b = "http://" . implode( "/" , $a );
//move uploaded file in to target folder
move_uploaded_file($myFile["tmp_name"][$i],$target_file);
//image path
$user_pic_path = $b . "/" . $target_file;
//add image path in one array by using array push function
array_push($image_array,$user_pic_path);
}
// single image path joined with semicolumn by using implode function
$real_images_path = implode(",",$image_array);
}
?>
VIEW YOUR UPLOADED IMAGES:
<?php
if(isset($_POST['submit']))
{
$img_array = explode(",",$real_images_path);
?>
<?php
}
else
{
}
?>

No comments: