I have an upload script which works just fine.
I'm trying to write a resize function into the script which will
distinguish between portrait and landscape images, resize accordingly and then continue
the upload.
Trouble is, although the new portion of the script 'seems' to work, (it prints the original
size and then the resized size and they are correct) the uploaded image is
not being resized.
The 'new' (resize) section starts at line 31.
All and any advice on what I think is just a small syntax issue much appreciated.
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 ) {
$success_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
list($width, $height, $type, $attr)=getimagesize($_FILES['fileField']['tmp_name']);
$ht=$height;
$wd=$width;
print $height . " ";
print $width . " ";
if($width>780){
$diff = $width-780;
$percnt_reduced = (($diff/$width)*100);
$ht = $height-(($percnt_reduced*$height)/100);
$wd= $width-$diff;
}
if($height>480){
$diff = $height-480;
$percnt_reduced = (($diff/$height)*100);
$wd = $width-(($percnt_reduced*$width)/100);
$ht= $height-$diff;
print $ht . " ";
print $wd . " ";
}
// 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);
}
$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.</span>';
} 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.';
}