Handling Images

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
BigAbe
Forum Commoner
Posts: 66
Joined: Fri Mar 31, 2006 7:41 pm

Handling Images

Post by BigAbe »

Aloha everyone!

I'm trying an image upload program where the user will upload the image via a form on page 1.

Then on page two, I have the following code to do some resizing:

Code: Select all

$filename = $_FILES['temp']['name']; 
$temporary_name = $_FILES['temp']['tmp_name']; 
$mimetype = $_FILES['temp']['type']; 
$filesize = $_FILES['temp']['size']; 

if ($filename != ""){
	//Open the image using the imagecreatefrom..() command based on the MIME type. 
	switch($mimetype) { 
    	case "image/jpg": 
	    case "image/jpeg": 
		case "image/pjpeg": 
	        $i = imagecreatefromjpeg($temporary_name); 
	        break; 
	    case "image/gif": 
	        $i = imagecreatefromgif($temporary_name); 
	        break; 
	    case "image/png": 
	        $i = imagecreatefrompng($temporary_name); 
    	    break; 
	} 

	
	

	//Specify the size of the thumbnail 
	$dest_x = 250; 
	$dest_y = 250; 
	
	//Is the original bigger than the thumbnail dimensions? 
	if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) { 
	    //Is the width of the original bigger than the height? 
	    if (imagesx($i) >= imagesy($i)) { 
	        $thumb_x = $dest_x; 
	        $thumb_y = imagesy($i)*($dest_x/imagesx($i)); 
	    } else { 
	        $thumb_x = imagesx($i)*($dest_y/imagesy($i)); 
	        $thumb_y = $dest_y; 
	    } 
	} else { 
	    //Using the original dimensions 
	    $thumb_x = imagesx($i); 
	    $thumb_y = imagesy($i); 
	} 
	
	//Generate a new image at the size of the thumbnail 
	$thumb = imagecreatetruecolor($thumb_x,$thumb_y); 
	
	//Copy the original image data to it using resampling 
	imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i)); 
	
	//imagetracker id
	$tempid = rand(1,99999);
	
	//Save the thumbnail 
	imagejpeg($thumb, "../tempimages/$tempid.jpg", 80);
I want this to be a preview page, and if the user wants to continue, they click "continue" and then the very same image is passed on to the next page.

I tried passing $filename, $temporary_name, $mimetype, and $filesize to the next page, but it wouldn't work.

Is there some way to pass the exact same $_FILES info to the next page so I can work with it in a similar method there?

Thank you!

-- Abe --
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

why don't you use move_uploaded_file() and save the file on the server...then you can do whatever you want with it across as many pages as you'd like.
Post Reply