spires Posted June 4, 2007 Share Posted June 4, 2007 Hi Everyone. I'm haveing a problem uploading images on P.C. The script is working fine on my MAC, but is throwing up errors on my PC? I think its something to do with: $userfile_tmp1 = $_FILES['text_img']['tmp_name']; But i'm not to sure what. Heres the error: Problem In opening Source Image for thumbnail1 Any ideas please? $att_name = $_FILES['text_img']['name']; if ($att_name==''){ }else{ $random_digit=rand(00000000,99999999); $width = 120; // size of width $lwidth = 120; //large thumb width $filedir = 'text_img/orig/'; // the directory for the original image $thumbdir = 'text_img/thumbs/'; // the directory for the thumbnail image $largedir = 'text_img/large/'; // the directory for the large image $prefix = ''; // the prefix to be added to the original name $maxfile = '1000000'; // max file size $mode = octdec('0666'); // octdec -- Octal to decimal. // The mode parameter consists of three octal number components specifying access restrictions for the owner, // the user group in which the owner is in, and to everybody else in this order. e.g (666) $userfile_name1 = $_FILES['text_img']['name']; $userfile_tmp1 = $_FILES['text_img']['tmp_name']; $userfile_size1 = $_FILES['text_img']['size']; $userfile_type1 = $_FILES['text_img']['type']; $imgsize = @getimagesize($userfile_tmp1); // sticks in the image size into the array ($imgsize) $origwidth = $imgsize[0]; // = image width $origheight = $imgsize[1]; // = image height $ratio = ($origheight/$origwidth); // $height = ($width * $ratio); $lheight = ($lwidth * $ratio); $type = 0; if(strcmp($userfile_type1, "image/jpeg")==0){ $new_img_name1 = $id.$random_digit.".jpg"; $type = 1; } // $prod_img = the image folder and the image and name $prod_img = $filedir.$new_img_name1; // $prod_img_thumb = the thumb folder, the prefix (if you want it) and the image and name $prod_img_thumb = $thumbdir.$new_img_name1; $prod_img_lthumb = $lthumbdir.$new_img_name1; //move_uploaded_file -- Moves an uploaded file to a new location. //move the uploaded file to the image folder with a tempory name. if(move_uploaded_file($userfile_tmp1, $prod_img)){ $uploaded = "Image Uploaded<br>"; } else{ $uploaded1 = "Upload Failed<br>"; } // chmod -- Changes file mode, // set the user interface for the image chmod ($prod_img, $mode); // getimagesize -- Get the size of an image // find the size of the original image $sizes = getimagesize($prod_img); $new_height = $height; $new_width = $width; $new_lheight = $lheight; $new_lwidth = $lwidth; // $new_width = abs($new_height/$aspect_ratio); // this code will only change the height, and make the width in ratio $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem Creating Thumbnail1'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image for thumbnail1'); ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing image to thumbnail1'); ImageCopyResampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $sizes[0], $sizes[1]) or die('Problem In resampling1'); ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem saving thumbnail1'); imagedestroy($destimg); $alignment = $_POST['alignm']; $sql = "INSERT INTO text_img (Tname, Tpage, alignment) VALUES ('$new_img_name1', '$selected_id', '$alignment')"; $query = mysql_query($sql) or die (mysql_error()); } } Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/54187-solved-code-wont-work-on-pc-only-on-mac/ Share on other sites More sharing options...
spires Posted June 5, 2007 Author Share Posted June 5, 2007 Hi I posted yesterday. Just seeing if anyone today has any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/54187-solved-code-wont-work-on-pc-only-on-mac/#findComment-268208 Share on other sites More sharing options...
spires Posted June 5, 2007 Author Share Posted June 5, 2007 Here is what the problem was. for some reason PCs or maybe only IE names the '$_FILES['image']['type'];' = image/pjpeg but on MAC and maybe other browsers '$_FILES['image']['type'];' = image/jpeg I don't know why IE adds an extra 'p' before the jpeg, but i does. So, this is how to get around it. $type = 0; if(strcmp($userfile_type, "image/jpeg")==0){ $new_img_name = $random_digit.".jpg"; $banner_type='jpg'; $type = 1; }elseif (strcmp($userfile_type, "image/pjpeg")==0){ $new_img_name = $random_digit.".jpg"; $banner_type='jpg'; $type = 2; } Quote Link to comment https://forums.phpfreaks.com/topic/54187-solved-code-wont-work-on-pc-only-on-mac/#findComment-268259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.