UrmilaP
12-29-2010, 05:52 AM
I want script for multiple Image uploading on a single page.
VijayKanta
12-29-2010, 06:13 AM
HTML and PHP cannot do what you are asking for. You either need to develop a Flash based or Java based additional applet program to achieve multiple images select from your image upload popup.
However, things being always tricky and solvable, we could have more than one "file" type input element for the form which can allow us to upload more than one image from a form.
<input type="file" name="image1" /> Image 1<br />
<input type="file" name="image2" /> Image 2<br />
<input type="file" name="image3" /> Image 3... and so on
now PHP
<?php
$im1 = $_FILES['image1']['name'];
$im2 = $_FILES['image2']['name'];
$im3 = $_FILES['image3']['name'];
?>
I suppose you have enough PHP knowledge to do the rest of the stuff. If not, I will try providing all code.
bluewalrus
12-29-2010, 06:17 AM
http://code.google.com/p/swfupload/ Can handle multiple file uploads in a single upload button click if you want something else please be more specific.
james438
12-29-2010, 01:24 PM
You can use html and php to upload multiple images. Sorry, but I am being a little lazy in not pruning the code to only do what you want. Basically, the second file will test the file to see that what was uploaded is indeed an image, convert the filename to lowercase, upload the original image(s) to the folder you have already created named "screenshots" and a thumbnail version to the folder called "thumbs".
File1
<div align="center"><hr>
<form enctype="multipart/form-data" action="file2.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="50000000">
<input type="file" name="pix[]" size="60" id ="pix[]"><br>
<input type="file" name="pix[]" size="60" id ="pix[]"><br>
<input type="file" name="pix[]" size="60" id ="pix[]"><br>
<input type="file" name="pix[]" size="60" id ="pix[]"><br>
<input type="file" name="pix[]" size="60" id ="pix[]"><br>
<input type="file" name="pix[]" size="60" id ="pix[]">
<p><input type="submit" name="Upload" value="Upload Picture">
</form>
</div>
file2
<?php
$loop=1;
print $_FILES['pix']['name'][$loop];
function or_f($a, $b) {
return $a || $b;
}
function file_has_extension($fn, $ext) {
if(is_array($ext))
return array_reduce(array_map(create_function('$a', 'return file_has_extension(\'' . $fn . '\', $a);'), $ext), 'or_f', false);
else
return stripos($fn, '.' . strtolower($ext)) === strlen($fn) - strlen($ext) + 1;
}
$image_extensions = array(
'png',
'jpg',
'jpeg',
'gif',
'bmp'
);
if(!isset($_POST['Upload']))
{
include("file1.php");
}
else
{$loop="-1";while ($loop<5){$loop++;
if ($_FILES['pix']['name'][$loop]=="") continue;
if($_FILES['pix']['tmp_name'][$loop] == "none")
{
echo "<b>File did not successfully upload. Check the
file size. File must be less than 500K.<br>";
include("picform.php");
exit();
}
if(file_has_extension($_FILES['pix']['name'][$loop], $image_extensions))
{
echo "<b>File is not a picture. Please try another
file.</b><br>";
include("file1.php");
exit();
}
else
{
$destination = $_FILES['pix']['name'][$loop];
$destination = strtolower($destination);
$rest=substr($destination,-3,3);
$temp_file = $_FILES['pix']['tmp_name'][$loop];
move_uploaded_file($temp_file,$destination);
echo "<p><b>The file has successfully uploaded: echo http://www.mysite.com/images/screenshots/$destination</b>
{$_FILES['pix']['name'][$loop]}
({$_FILES['pix']['size'][$loop]})</p>";
$img="http://www.mysite.com/images/screenshots/$destination";
$img = $destination;
$width = "300px";
$height = "";
// Get new dimensions
list($width1, $height1) = getimagesize($img);
if ($width =="") {$j=$height/$height1; $width = $width1 * $j;}
if ($height=="") {$j=$width/$width1; $height = $height1 * $j;}
$new_width = $width;
$new_height = $height;
// Resample
$image_p = imagecreatetruecolor($width, $height);
if ($rest=="png") {$image = imagecreatefrompng($img);}
elseif ($rest=="jpg") {$image = imagecreatefromjpeg($img);}
elseif ($rest=="peg") {$image = imagecreatefromjpeg($img);}
elseif ($rest=="gif") {$image = imagecreatefromgif($img);}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width1, $height1);
// Output
$img=preg_replace('/h.*\//','',$img);
$img=strtolower($img);
$dest="../thumbs/$img";
if ($rest=="gif")imagegif($image_p,$dest);
elseif ($rest=="png")imagepng($image_p,$dest);
elseif ($rest=="peg")imagejpeg($image_p,$dest);
elseif ($rest=="jpg")imagejpeg($image_p,$dest);
}
}}
?>
You can add as many images at a time as you want by simply changing the value of ($loop<5) to 6 or higher in the second file and adding more
<input type="file" name="pix[]" size="60" id ="pix[]"><br>
lines to the first file. I could modify the second file a little so that there is never a need to modify ($loop<5) at all.
UrmilaP
01-03-2011, 07:16 AM
Thank you Vijay sir,
I am actually junior developer , but still I have done it, and it is working. .
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.