Hi,
I recently bought a baby album script. Unfortunately, the pictures aren't resized on uploading and are absolutlely massive!
I've tried for what seems like days now to add in code to resize a picture on upload but to no avail!
Most of the code I've see on resizing seems to be pretty much the same, something like this...
// temporary file created by PHP
$uploadedfile = $_FILES['photo']['tmp_name'];
// resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// resize the image
$newwidth=350;
$newheight=($height/$width)*400;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// resizing, copying from the original image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk.
$filename = "images/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
This is the code that I'm trying to fit it into:
require_once '../include/config.php';
require_once $_config['site_path'] . '/include/user_function.php';
if ($submit) {
$_var += $_POST;
$source = $_FILES['photo']['name'];
$ext = get_file_extension($_FILES['photo']['tmp_name']);
if ($ext != 'err') {
$temp2 = 1;
}
$check_max = check_max_photos();
$_form->isEmpty($source, 'Enter Photo File');
$_form->isEmpty($temp2, 'Enter A Valid Image File(JPG,GIF,PNG)');
$_form->isEmpty($title, 'Enter Photo Title');
$_form->isEmpty($description, 'Enter Photo Description');
$_form->isEmpty($category_id, 'Please Add A Category.');
$_form->isEmpty($check_max, 'Your number of photos Exceeds the limits.');
if ($_form->isError()) {
$_var['category'] = get_option(array(name => 'category', value=> 'category_id', option => 'category_name'),"where user_id ='$user_id'");
$_var['category'] = str_replace("value=\"$category_id\"","value=\"$category_id\" selected",$_var['category']);
$_var['error'] = "<font color='red'>" . join("<BR>",$_form->getErrorList()) . "</font>";
$_var['main_content'] = do_template('user_upload_photo.html');
}
else {
$db->query("INSERT INTO photos SET category_id = '$category_id', user_id = '$user_id', title = '$title', description = '$description'");
$photo_id = $db->insert_id();
$uploadpath = $_config['site_path'] . '/photos/';
$source = $_FILES['photo']['tmp_name'];
$file_name = "{$user_id}_" . "{$category_id}_" . "$photo_id" . ".$ext";
$dest = $uploadpath . $file_name;
if (move_uploaded_file($source, $dest ) ) {
} else {
echo 'File could not be stored.<BR>';
}
$db->query("UPDATE photos SET file_name = '$file_name' WHERE photo_id = '$photo_id'");
$_var['main_content'] = "Your Photo is Uploaded";
refresh('upload_photo.php');
}
}
else {
$_var['category'] = get_option(array(name => 'category', value=> 'category_id', option => 'category_name'),"where user_id ='$user_id'");
$_var['main_content'] = do_template('user_upload_photo.html');
}
echo do_template('main.html');
echo do_template('footer.html');
I know it's never ideal to try and slot code together like this!
The 'name' tag in the html form is photo so that's ok, and I can see that one problem is the file storage; the new code specifies the wrong place.
I've taken this line out and tried placing the snippet in various places, calling it as a function from the included files listed at the top of the main code block, again at different places in the script.
Can anyone point me the right direction please before I go completely bananas!!??
Many thanks
Luds