| 
	
 | 
 Posted by Erwin Moller on 09/05/07 15:14 
xx75vulcan wrote: 
> Hi, 
>  
> I've got a PHP Upload Form that works great, unless that is, the image 
> your uploading has been modified through a photo editing software. 
>  
> Example: if I upload the image straight from a camera or other, it 
> uploads fine. However, If I want to rotate the image, or resize it 
> with photoshop or simmilar, making sure to save it again as a jpg, the 
> PHP upload won't upload the image. 
>  
> It's like editing the image somehow changes it's mime type or 
> something?! 
 
Hi Vulcan, 
 
Maybe. 
 
> Any ideas? 
 
I ALWAYS start debugging such issues with: 
 
echo "<pre>"; 
print_r($_FILES); 
echo "</pre>"; 
exit; 
 
Then compare the output of your uneditted and editted version. 
Do you see any differences? 
 
That will probably give you a hint. 
 
 
And do NOT rely too much on mimetype. 
from php.net: 
 
$_FILES['userfile']['type'] 
     The mime type of the file, if the browser provided this  
information. An example would be "image/gif". This mime type is however  
not checked on the PHP side and therefore don't take its value for granted. 
 
Hope that helps. 
 
Regards, 
Erwin Moller 
 
>  Here's my upload script: 
>  
> <?php 
> if($_POST["upload"])  //Check to see if submit was clicked 
> { 
> 	// Get the details of "imagefile" 
> 	$filename = $_FILES['imagefile']['name']; 
> 	$temporary_name = $_FILES['imagefile']['tmp_name']; 
> 	$mimetype = $_FILES['imagefile']['type']; 
> 	$filesize = $_FILES['imagefile']['size']; 
>  
> 	//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; 
> 	} 
>  
> 	//Delete the uploaded file 
> 	unlink($temporary_name); 
>  
> //Specify the size of the thumbnail 
> 	$dest_x = 350; 
> 	$dest_y = 350; 
>  
> 	//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)); 
>  
> 	//Save the thumbnail 
> 	imagejpeg($thumb, "../images/$filename", 80); 
>  
> 	//Display FileName 
> 	Print "Value for Image field: $filename"; 
> 	$added =true; 
> } 
> ?> 
>  
> <html> 
>         <form action="upload.php" method="POST" enctype="multipart/ 
> form-data"> 
> 	<input type="hidden" name="MAX_FILE_SIZE" value="200000"> 
> 	<input type="file" name="imagefile"> 
> 	<input type="submit" name="upload" value="Upload Image"> 
> 	</form> 
> </html> 
>
 
  
Navigation:
[Reply to this message] 
 |