Jump to content

Cant get images to upload corectly - In way over my head...


wbent79

Recommended Posts

This code runs 4 times once for each photo to be uploaded, the problem is it will only show jpeg images uploaded. Any other image type does not show up.

 

I have tried adding different image types to the script but no change.

 

Please help!!!

 

Thanks!

 

<?php 

if(isset($_FILES["photo1"]["tmp_name"])&& $_FILES["photo1"]["tmp_name"]!="")
	{
		$file_temp = $_FILES['photo1']['tmp_name'];	
		$original_file_name = $_FILES['photo1']['name'];

		$new_file_name = time().$original_file_name;			
		$filepath = "../temp_files/".$new_file_name;				

		move_uploaded_file( $file_temp , $filepath );

		// Creating Full Image
		$thumbnail = "FULL".$new_file_name;
		$thumbnailpath = "../temp_files/".$thumbnail;			
		$imageBoxSize = 207;
		list($fileWidth,$fileHeight, $image_type)=getimagesize($filepath);								

		if($fileHeight > $fileWidth)
			{$unit = $fileWidth/$fileHeight;		$width = $imageBoxSize * $unit;		$height = $imageBoxSize;}
		else
			{$unit = $fileHeight/$fileWidth; 	$height = $imageBoxSize * $unit;	$width = $imageBoxSize;}	

   			switch ($image_type)
		{
			case 1: $src = imagecreatefromgif($filepath); break;
			case 2: $src = imagecreatefromjpeg($filepath);  break;
			case 3: $src = imagecreatefrompng($filepath); break;
			default:  trigger_error('Unsupported filetype!', E_USER_WARNING);  break;
		}
		$tmp = imagecreatetruecolor($width,$height);
		imagecopyresampled($tmp,$src,0,0,0,0,$width,$height,$fileWidth,$fileHeight);
		if(imagejpeg($tmp,$thumbnailpath,100));

		//Creating Thumbnail
		$thumbnail = "TN".$new_file_name;
		$thumbnailpath = "../temp_files/".$thumbnail;			
		$imageBoxSize = 50;				
		list($fileWidth,$fileHeight)=getimagesize($filepath);						

		if($fileHeight > $fileWidth)
			{$unit = $fileWidth/$fileHeight;		$width = $imageBoxSize * $unit;		$height = $imageBoxSize;}
		else
			{$unit = $fileHeight/$fileWidth; 	$height = $imageBoxSize * $unit;	$width = $imageBoxSize;}	

		$src = imagecreatefromjpeg($filepath);
		$tmp = imagecreatetruecolor($width,$height);
		imagecopyresampled($tmp,$src,0,0,0,0,$width,$height,$fileWidth,$fileHeight);
		if(imagejpeg($tmp,$thumbnailpath,100));	

		//Creating MainPage Thumbnail
		$thumbnail = "MAIN".$new_file_name;
		$thumbnailpath = "../temp_files/".$thumbnail;			
		$imageBoxSize = 87;				
		list($fileWidth,$fileHeight)=getimagesize($filepath);						

		if($fileHeight > $fileWidth)
			{$unit = $fileWidth/$fileHeight;		$width = $imageBoxSize * $unit;		$height = $imageBoxSize;}
		else
			{$unit = $fileHeight/$fileWidth; 	$height = $imageBoxSize * $unit;	$width = $imageBoxSize;}	

		$src = imagecreatefromjpeg($filepath);
		$tmp = imagecreatetruecolor($width,$height);
		imagecopyresampled($tmp,$src,0,0,0,0,$width,$height,$fileWidth,$fileHeight);
		if(imagejpeg($tmp,$thumbnailpath,100));


		//Deleting Original File
		unlink($filepath);

		$_SESSION['photo1'] = $new_file_name;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.