Page 1 of 1
How do you add multiple image uploads in one go?
Posted: Fri Feb 14, 2014 1:21 pm
by simonmlewis
I know how to upload PDFs, Docs, Images etc, but I need to be able to click Browse, and select all 50+whatever amount of image files at a time, and for each one to be renamed, and uploaded to a folder, and to be inserted, row by row, into a database.
How is it done?? Is there some special PHP term or method used?
Re: How do you add multiple image uploads in one go?
Posted: Fri Feb 14, 2014 1:28 pm
by simonmlewis
Re: How do you add multiple image uploads in one go?
Posted: Mon Feb 17, 2014 4:58 am
by simonmlewis
I've found a script that works, and adapted it a bit - the one thing it doesn't do is create thumbnails as it uploads. This page will be used to show uploaded scanned testominals, so they will be around 400-1mb per upload. So I need to reduce them to about 160px wide.
I have a script I use that resizes per image, but it's a long script, and this one is already very short just for multiple uploads.
So how might one adapt this to create a separate image to upload to /images/test/small ?
Code: Select all
echo "<div class='head'>Upload multiple Testominals</div>";
if(isset($_FILES['files'])){
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$query="INSERT into testimonial_uploads (`filename`) VALUES('$file_name'); ";
$desired_dir="images/test";
echo "Please wait a moment while the system uploads all files.";
if(empty($errors)==true){
if(is_dir("$desired_dir/".$file_name)==false)
{
move_uploaded_file($file_tmp,"images/test/".$file_name);
}
else
{ //rename the file if another one exist
$new_dir="images/test/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
mysql_query($query);
}else{
print_r($errors);
}
}
if(empty($error)){
echo "<script>
window.location.replace('/a_multiupload&success=yes')
</script>";
}
}
if ($success == "yes")
{
echo "All files have been uploaded.";
}
echo "<form action='' method='POST' enctype='multipart/form-data'>
<input type='file' name='files[]' multiple/>
<input type='submit' value='Upload files'/>
</form>";
Re: How do you add multiple image uploads in one go?
Posted: Mon Feb 17, 2014 6:05 am
by Celauran
Take a look at
WideImage.
Re: How do you add multiple image uploads in one go?
Posted: Mon Feb 17, 2014 6:58 am
by simonmlewis
Pardon my ignorance here, but I am seeing a set of folders. Nothing to tell me what it is, nor how to download them?
I take it my existing script cannot be simply altered to enable image resizing/duplication?
Re: How do you add multiple image uploads in one go?
Posted: Mon Feb 17, 2014 7:17 am
by Celauran
It's a GitHub repo. You can clone the repo or use the "Download Zip" button in the right sidebar. It's an image resizing library that will do exactly what you want.
Re: How do you add multiple image uploads in one go?
Posted: Mon Feb 17, 2014 7:23 am
by simonmlewis
So it also resizing when you select multiple images at one time?
My script does everything, except the resizing. At this very moment I am trying to get the resizing side working, so don't really want a whole new script, just the "resize" part embedded in mine.
Re: How do you add multiple image uploads in one go?
Posted: Mon Feb 17, 2014 7:45 am
by simonmlewis
Code: Select all
<?php
include('/SimpleImage.php');
$image = new SimpleImage();
$image->load('images/test/0_MG_8830.jpg');
$image->resizeToWidth(250);
$image->save('images/test/small/0_MG_8830.jpg');
echo "<img src='/images/test/small/0_MG_8830.jpg' />";
?>
Found this. Which generates the thumbs if they don't exist. I already have script that will delete each one if needed, so job done!