envexlabs Posted April 1, 2008 Share Posted April 1, 2008 Hey, I have an image uploader script which uploads then resizes the image. The script works fine except when users are trying to upload an image from a camera. This is the error people are getting: Thanks, envex Link to comment https://forums.phpfreaks.com/topic/98997-problems-with-image-upload/ Share on other sites More sharing options...
micah1701 Posted April 1, 2008 Share Posted April 1, 2008 what's the error say? could you show us the snippet of code that gives that error? did you write the script or did you find it online somewhere? My guess is that the script is only set to work for .jpg or .gif images and data coming from a camera is either in raw format or has lots of extra meta data that the script can't handle. Link to comment https://forums.phpfreaks.com/topic/98997-problems-with-image-upload/#findComment-506583 Share on other sites More sharing options...
envexlabs Posted April 1, 2008 Author Share Posted April 1, 2008 if(empty($_FILES['pic']['name'])){}else{ //$ext = explode('.', $_FILES['pic']['name']); //puts the array into a variable so that it can be inputed into the database as a name.ext instead of Array[] $name = $_SESSION['username'] . '_' . $_FILES['pic']['name']; //sets the directory and name for the file $uploaddir = 'profile_pics/'; $uploadfile = $uploaddir . $name; if (move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile)) {} else { echo "Picture could not be uploaded"; } //changes the permissions of the file //chmod($uploadfile, 0777); $pic = $uploadfile; //this shrinks the image if the orignal is too big $org_size = getimagesize('http://www.yournightyourcity.com/' . $pic); //takes the larger size of the width and height and applies the //formula accordingly...this is so this script will work //dynamically with any size image $mywidth = $org_size[0]; $myheight = $org_size[1]; $target = 230; $percentage = ($target / $mywidth); //gets the new value and applies the percentage, then rounds the value $mywidth = round($mywidth * $percentage); $myheight = round($myheight * $percentage); $source_path = $pic; $destination_path = $pic; $ext = strrchr($pic, "."); $new_width= $mywidth; //Image width Change if needed $new_height= $myheight; //Image height Change if needed $destimg=imagecreatetruecolor($new_width,$new_height) or die("Problem In Creating image"); switch($ext) { case '.gif': $srcimg = imagecreatefromgif($pic) or die("Problem In opening Source Image"); break; case '.jpg': $srcimg = imagecreatefromjpeg($pic) or die("Problem In opening Source Image"); break; case '.jpeg': $srcimg = imagecreatefromjpeg($pic) or die("Problem In opening Source Image"); break; case '.png': $srcimg = imagecreatefrompng($pic) or die("Problem In opening Source Image"); break; } ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing"); Imagejpeg($destimg,$destination_path,100) or die("Problem In saving"); $org = 'profile_pics/'.$name; $thumb = 'profile_pics/thumbs/'.$name; $front_thumb = 'profile_pics/front_thumbs/'.$name; $updatepic = mysql_query('UPDATE `member_info` SET `pic` = \'' . $pic . '\' WHERE `mem_id` = ' . $_POST['mem_id'] . ''); $matt_ext = explode('.', $ext); //creates memberpage thumb cropImage(125, 150, $org, $matt_ext[1], $thumb); //creates frontpage thumb cropImage(135, 105, $org, $matt_ext[1], $front_thumb); //changes permissions for all images chmod($pic, 0755); chmod($thumb, 0755); chmod($front_thumb, 0755); } Link to comment https://forums.phpfreaks.com/topic/98997-problems-with-image-upload/#findComment-506585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.