Resizing an image on upload
Posted: Fri Jun 11, 2010 1:19 pm
I made an image uploader, but the client doesnt want the users to have to manually change the height & width (50x50px), he wants it done upon upload. Anyone have a simple block of code todo this? Here is what I got so far..
I commented out where I believe the resize should go. Thanks guys, this place is honestly the best place togo for any answers (besides google..)
Code: Select all
if ($_FILES['upload'] != ''){
if ( (($_FILES['upload']['type'] == 'image/gif') || ($_FILES['upload']['type'] == 'image/png') || ($_FILES['upload']['type'] == 'image/jpeg') || ($_FILE\
S['upload']['type'] == 'image/pjpeg')) && ($_FILES["file"]["size"] < 50000)){
if($_FILES['upload']['error'] > 0){
$smarty->assign('error', 'Return Code: '.$_FILES['upload']['error'].'');
} else {
if (file_exists("../images/editors/" . $_FILES['upload']['name'])) {
$smarty->assign('error', 'The file you tried to upload ('.$_FILES['upload']['name'].') already exists. ');
} else {
//IMAGE RESIZE BLOCK SHOULD GO IN HERE BEFORE MOVING TO SAVED DIRECTORY
//JUST NOT SURE HOW TO DO IT
//ALL HELP IS APPRECIATED! :)
if (!move_uploaded_file($_FILES['upload']['tmp_name'], '../images/editors/'.$_FILES['upload']['name'])){
$smarty->assign('error', 'Error moving the file.');
} else {
$smarty->assign('notice', 'Stored in: images/editors/'.$_FILES['upload']['name'].'');
}
}
}
$profile_image = $_FILES['upload']['name'];
} else {
$smarty->assign('error', 'Invalid file. File must be an image (.jpg, .jpeg, .png, .gif).');
}
}