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
PHP Code:
<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 Code:
<?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.
Bookmarks