Shrinking an Image on Upload..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dannysolomons
Forum Newbie
Posts: 2
Joined: Tue Mar 18, 2008 6:10 am
Location: Margate, Kent

Shrinking an Image on Upload..

Post by dannysolomons »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
 
echo 'Upload result:<br>'; // At least one symbol should be sent to response!!!
 
$uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."../gallery/".$_GET['album']."/";
 
$target_encoding = "ISO-8859-1";
echo '<pre>';
if(count($_FILES) > 0)
{
    $arrfile = pos($_FILES);
    $uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name']));
 
    if (move_uploaded_file($arrfile['tmp_name'], $uploadfile))
       echo "File is valid, and was successfully uploaded.\n";
}
else
    echo 'No files sent. Script is OK!'; //Say to Flash that script exists and can receive files
 
echo 'Here is some more debugging info:';
print_r($_FILES);
 
echo "</pre>";
 
?>

does anyone have any idea how i could implement a image reducer into this script, to 600 * 600. tried editing it from snippets i have and have no luck..
thanks..


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Re: Shrinking an Image on Upload..

Post by thomas777neo »

Have a look at this link:

Image Resize Class
http://scripts.ringsworld.com/image-han ... e.php.html

Here is how I used it, this code is out of context, but you'll get the idea:

Code: Select all

 
$_POST["{$var_prefix}icon"] = $icon_upload_path."/".$_FILES["{$var_prefix}icon"]["name"];
 
$image = new hft_image($_POST["{$var_prefix}icon"]); // set class to open uploaded file
$image-> resize($max_icon_height, $max_icon_width, '-'); // resize the image
$new_file = $icon_upload_path."/".time().$_FILES["{$var_prefix}icon"]["name"];
$image-> output_resized($new_file,$save_image_as); // save the resized image
Works pretty well.
dannysolomons
Forum Newbie
Posts: 2
Joined: Tue Mar 18, 2008 6:10 am
Location: Margate, Kent

Re: Shrinking an Image on Upload..

Post by dannysolomons »

cheers mate
ideal i got the idea, should help out a treat.

thanks
Post Reply