Multiple upload
Posted: Sat Jan 30, 2010 5:13 pm
Hi all,
I've got an upload script which works nicely - uploads an image, prints a success
message and a thumbnail of the image you just uploaded.
I'd like to "convert" this script to handle multiple uploads (5 images at once) and am
unsure how to go about it so all and any advice very much appreciated.
(my original upload code below)
Best wishes
Monty
I've got an upload script which works nicely - uploads an image, prints a success
message and a thumbnail of the image you just uploaded.
I'd like to "convert" this script to handle multiple uploads (5 images at once) and am
unsure how to go about it so all and any advice very much appreciated.
(my original upload code below)
Best wishes
Monty
Code: Select all
if ((!empty($_FILES['fileField'])) && ($_FILES['fileField']['error'] == 0)){
$image = $_FILES['fileField']['name'];
$filename = stripslashes($_FILES['fileField']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
//Filetype check
if (!in_array($extension,$acceptableextensions)){
exit("Upload failed.<BR>Unacceptable file type.<br. Use only jpg, jpeg, png or fig formats");
echo '<h1>Only try to upload .jpg, .jpeg, .png and .gif files!</h1>';
$errors=1;
//Filesize check
} else if ($_FILES['fileField']['size'] > $maxfilesize ) {
$error_msg = 'Ooops - your image was too large,<br> 250kb Maximum. Please try again.';
unlink($_FILES['fileField']['tmp_name']);
} else {
// rename the picture incrementally
$extension = getExtension($filename);
$extension = strtolower($extension);
$groovy = sizeof(glob("members/$id/images/*"));
$groovy = ++$groovy;
$image_name=$groovy.'.'.$extension;
$newname="".$image_name;
$gowhere = mysql_real_escape_string($_POST['gowhere']);
// NOW make the resize call !
//img_resize ($_FILES ['fileField'] [ 'name'], $_FILES [ 'fileField'] [ 'tmp_name'], 25, $newname);
// INSERT image into the DB
$sql = mysql_query("INSERT INTO pictures
(UID,filename,dirpath,gallery,dtadded)
VALUES ('$id','$newname','/members/$id/images/$newname','$gowhere',now())")
or die (mysql_error());
$place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "members/$id/images/".$newname);
chmod ("members/$id/images/$newname", 0644);
////////// MY RESIZE EFFORT !!
//$imagepath = $newname;
$save = "members/$id/images/" .$newname; //new file to save
$file = "members/$id/images/" .$newname; //original file
list($width, $height) = getimagesize($file) ;
$modwidth = 750;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "members/$id/images/sml_" . $newname; //This is the new file you saving
$file = "members/$id/images/" . $newname; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 80;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$thumbToPrint = "<img src='members/$id/images/sml_".$newname."'>";
//REDUNDANT NOW but keep for reference... NOW WRITE THE .txt FILE IN THE APPROPRIATE GALLERY FOLDER
//$myFile = "images/gallery/".$_POST ['gowhere']. "/gallarray.txt";
//$fh = fopen($myFile, 'a+') or die("can't open file");
//$stringData = "members/".$id."/images/".$newname .",";
//fwrite($fh, $stringData);
//fclose($fh);
}
$success_msg = '<span class="Big_Orange_Times">Your image has been uploaded. it may take a few moments to appear in your gallery, please be patient.<br>';
} else if ((!empty($_FILES['fileField'])) && ($_FILES['fileField']['error'] == 4)){
//Error code 4: No image uploaded
$error_msg = 'Please browse for an image before you press Go.';
}