Jump to content

PHP 4 - Image Uploader - Just for JPEG and PNG


kvnmck18

Recommended Posts

I know this is a "security risk" of sorts... but any ideas on making a PHP image uploader (for PHP 4); when image is uploaded it limits the image to a max height and width (while still keeping it in proportion to it's original dimensions) and also created a second image that is the same image just scalled down more to a smaller max height & width dimension (to be used as a thumbnail).I'm currently look at imagecreatefrompng() and imagecreatefromjpg() funtions, along with php upload functions, imagecopyresized().Sugguestions? Any previous codes floating around that I can work with?Thanks~

Link to comment
Share on other sites

I have this so far as a starter this will work for making a thumbail 50% smaller:

<?php$filename = 'image.jpg';$percent = 0.5;header('Content-type: image/jpeg');list($width, $height) = getimagesize($filename);$newwidth = $width * $percent;$newheight = $height * $percent;$thumb = imagecreatetruecolor($newwidth, $newheight);$source = imagecreatefromjpeg($filename);imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);imagejpeg($thumb);?>

This helps in sorts but instead of a percent I want it to be like "$height < 50px"...to set a max height then get the ratio of what the difference is and make the width be in proportion.Aren't they similar? Send it... let me try it.

Link to comment
Share on other sites

Here is the complete code:http://www.manchine.net/steve/files/gallery.zipThis was sort of an experimental project for me, so there are a few things I do that I normally wouldn't. The entire thing is all in the index.php file (except for some includes), and it saves pictures in the database. You can execute the create_db.php file to set up the database after you modify the db_con.php file. The setup and usage instructions are in the index.php file. There are a few variables to edit in index.php as well. You will probably be interested in the add_image function inside functions.php.Let me know if you have questions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...