We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

uploading images in php

is there a way to resize an image after you have uploaded it using php? suppose i want to restrict the width and height of my images to 1000 and 800 respectively what code to i add to the following code snippet?

$tmp_file = $_FILES['file_upload']['tmp_name'];
        $target_file = basename( $_FILES['file_upload']['name'] );
        $upload_dir = IMAGE_DIR;
        
        if ( move_uploaded_file( $tmp_file, IMAGE_DIR . "/" . $target_file ) ) {
            $message = "File has been successfully uploaded.";
        } else {
            $error = $_FILES['file_upload']['error'];
            $message = $upload_errors[$error];       
        }
3
Contributors
2
Replies
21 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
dinhunzvi
Junior Poster in Training
74 posts since Jul 2010
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

Depending on what you have installed, you can use the GD library or ImageMagick. You can search this forum for examples.

pritaeas
Posting Prodigy
Moderator
9,317 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86

As pritaeas suggested, you can make sure you have the GD library and PHP5, then use the either the Simple Image class by Simon Jarvis and/or the Resize Class by Jarrod Oberto with the following kind of call:

$image->load($uploadedfile);
$image->resize(width,height);
$image->save($pathtoresizedimagefilename);
kamili
Newbie Poster
3 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0775 seconds using 2.68MB