How do you add multiple image uploads in one go?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do you add multiple image uploads in one go?
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?
How is it done?? Is there some special PHP term or method used?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you add multiple image uploads in one go?
This might work:
http://www.w3bees.com/2013/02/multiple- ... h-php.html
http://www.w3bees.com/2013/02/multiple- ... h-php.html
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you add multiple image uploads in one go?
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 ?
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>";Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you add multiple image uploads in one go?
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?
I take it my existing script cannot be simply altered to enable image resizing/duplication?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you add multiple image uploads in one go?
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.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you add multiple image uploads in one go?
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you add multiple image uploads in one go?
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' />";
?>Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.