Upload image - create thumbnail - not working on MAC

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
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Upload image - create thumbnail - not working on MAC

Post by tsg »

I have an upload script that uploads the image and creates a thumbnail. I have one customer that is using a mac and says that the thumbnail is not being created.

Anyone now of any known issues on this with a MAC?

Thanks,
Tim
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

most likely to be the filetype header being different to pc - if you are testing
$_FILES['field']['type']
for maybe "image/jpeg" or such then in many cases it will barf.

$arg = getimagesize($_FILES['field']['tmp_name'];
if($arg > 0 && $arg < 4)
{
// a gif / png or jpeg file
}

is a better way of testing.

we'd need to see the actual script or a var_dump($_FILES) after the mac upload to say any further.
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

You must be talking about this part:

Code: Select all

<?php
if($_FILES['image']['size']){
	if($_FILES['image']['type'] == "image/pjpeg"){
		$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
	}elseif($_FILES['image']['type'] == "image/x-png"){
		$im = imagecreatefrompng($_FILES['image']['tmp_name']);
	}elseif($_FILES['image']['type'] == "image/gif"){
		$im = imagecreatefromgif($_FILES['image']['tmp_name']);
	}
	if($im){
		if(file_exists("$FILENAME" . "$image_ext")){
			unlink("$FILENAME" . "$image_ext");
		}
    	ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$upload_folder . "/" . $FILENAME . $image_ext);
    	ImageDestroy ($im);
	}
 }

?>
The code might be a little messy, but is that the part you are talking about?
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Got it working .. thanks.
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

subnote: a nice (imo) approach to the conditional createfrom...? is

Code: Select all

$base_image = $_FILES['image']['tmp_name'];
$f_type = getimagesize($base_image);
$created_image = ($f_type[2] < 4)
                        ? ($f_type[2] < 3)
                            ? ($f_type[2] < 2)
                                ? ($f_type[2] < 1) ?
                                NULL
                            : imagecreatefromgif($base_image)
                        : imagecreatefromjpeg($base_image)
                    : imagecreatefrompng($base_image)
                    : NULL;
if($created_image !== NULL)
    {
     // we have a created image
Post Reply