zander1983 Posted June 7, 2011 Share Posted June 7, 2011 Im using imagejpeg to upload images. it works fine when i do a call using javascript and ajax. but when i call normally, with a page reload, it always returns false....very very frustrating as the exact same code will only work from an ajax call. anyone any idea? Link to comment https://forums.phpfreaks.com/topic/238730-imagejpeg-only-works-with-ajax-call/ Share on other sites More sharing options...
teynon Posted June 7, 2011 Share Posted June 7, 2011 Perhaps it's your code? (Hint Hint) P Y C O O O S U D T R E Link to comment https://forums.phpfreaks.com/topic/238730-imagejpeg-only-works-with-ajax-call/#findComment-1226740 Share on other sites More sharing options...
zander1983 Posted June 7, 2011 Author Share Posted June 7, 2011 the function is function uploadImage($fileName, $maxSize, $maxW, $fullPath, $relPath, $colorR, $colorG, $colorB, $maxH = null, $func, $shopItemId){ $folder = $relPath; $maxlimit = $maxSize; $allowed_ext = "jpg,jpeg,gif,png,bmp"; $match = ""; $filesize = $_FILES[$fileName]['size']; if($filesize > 0){ $filename = strtolower($_FILES[$fileName]['name']); $filename = preg_replace('/\s/', '_', $filename); if($filesize < 1){ $errorList[] = "File size is empty."; } if($filesize > $maxlimit){ $errorList[] = "File size is too big."; } $file_ext = preg_split("/\./",$filename); $allowed_ext = preg_split("/\,/",$allowed_ext); foreach($allowed_ext as $ext){ if($ext==end($file_ext)){ $match = "1"; // File is allowed $NUM = time(); $front_name = substr($file_ext[0], 0, 15); $newfilename = $front_name."_".$NUM.".".end($file_ext); $newthumbname = $front_name."_".$NUM."_s.".end($file_ext); $newfrontname = $front_name."_".$NUM."_f.".end($file_ext); $_SESSION[] = $newfilename; $filetype = end($file_ext); $save = $folder.$newfilename; $savethumb = $folder.$newthumbname; $savefront = $folder.$newfrontname; if(!file_exists($save)){ list($width_orig, $height_orig) = getimagesize($_FILES[$fileName]['tmp_name']); if($maxH == null){ if($width_orig < $maxW){ $fwidth = $width_orig; }else{ $fwidth = $maxW; } $ratio_orig = $width_orig/$height_orig; $fheight = $fwidth/$ratio_orig; $blank_height = $fheight; $top_offset = 0; }else{ if($width_orig <= $maxW && $height_orig <= $maxH){ $fheight = $height_orig; $fwidth = $width_orig; }else{ if($width_orig > $maxW){ $ratio = ($width_orig / $maxW); $fwidth = $maxW; $fheight = ($height_orig / $ratio); if($fheight > $maxH){ $ratio = ($fheight / $maxH); $fheight = $maxH; $fwidth = ($fwidth / $ratio); } } if($height_orig > $maxH){ $ratio = ($height_orig / $maxH); $fheight = $maxH; $fwidth = ($width_orig / $ratio); if($fwidth > $maxW){ $ratio = ($fwidth / $maxW); $fwidth = $maxW; $fheight = ($fheight / $ratio); } } } if($fheight == 0 || $fwidth == 0 || $height_orig == 0 || $width_orig == 0){ die("FATAL ERROR REPORT ERROR CODE [add-pic-line-67-orig] to <a href='http://www.atwebresults.com'>AT WEB RESULTS</a>"); } if($fheight < 45){ $blank_height = 45; $top_offset = round(($blank_height - $fheight)/2); }else{ $blank_height = $fheight; } } $newwidth = 75; // This can be a set value or a percentage of original size ($width) $newheight = 75; // This can be a set value or a percentage of original size ($height) $frontheight = 135; $frontwidth = 170; // Load the images $thumb = imagecreatetruecolor($newwidth, $newheight); $front = imagecreatetruecolor($frontwidth, $frontheight); $image_p = imagecreatetruecolor($fwidth, $blank_height); $white = imagecolorallocate($image_p, $colorR, $colorG, $colorB); imagefill($image_p, 0, 0, $white); switch($filetype){ case "gif": $image = @imagecreatefromgif($_FILES[$fileName]['tmp_name']); break; case "jpg": $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']); break; case "jpeg": $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']); break; case "png": $image = @imagecreatefrompng($_FILES[$fileName]['tmp_name']); break; } @imagecopyresampled($image_p, $image, 0, $top_offset, 0, 0, $fwidth, $fheight, $width_orig, $height_orig); // Resize the $thumb image. @imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width_orig, $height_orig); // Resize the $thumb image. @imagecopyresized($front, $image, 0, 0, 0, 0, $frontwidth, $frontheight, $width_orig, $height_orig); switch($filetype){ case "gif": if(!@imagegif($image_p, $save)){ $errorList[]= "PERMISSION DENIED [GIF]"; } if(!@imagegif($thumb, $savethumb)){ $errorList[]= "PERMISSION DENIED [GIF]"; } if(!@imagegif($front, $savefront)){ $errorList[]= "PERMISSION DENIED [GIF]"; } break; case "jpg": if(!@imagejpeg($image_p, $save, 100)){ $errorList[]= "PERMISSION DENIED [JPG]"; } if(!@imagejpeg($thumb, $savethumb, 100)){ $errorList[]= "PERMISSION DENIED [JPG]"; } if(!@imagejpeg($front, $savefront, 100)){ $errorList[]= "PERMISSION DENIED [JPG]"; } else{ $var = "in the else "; } break; case "jpeg": if(!@imagejpeg($image_p, $save, 100)){ $errorList[]= "PERMISSION DENIED [JPEG]"; } if(!@imagejpeg($thumb, $savethumb, 100)){ $errorList[]= "PERMISSION DENIED [JPEG]"; } if(!@imagejpeg($front, $savefront, 100)){ $errorList[]= "PERMISSION DENIED [JPEG]"; } break; case "png": if(!@imagepng($image_p, $save, 0)){ $errorList[]= "PERMISSION DENIED [PNG]"; } if(!@imagepng($thumb, $savethumb, 0)){ $errorList[]= "PERMISSION DENIED [PNG]"; } if(!@imagepng($front, $savefront, 0)){ $errorList[]= "PERMISSION DENIED [PNG]"; } break; } @imagedestroy($filename); }else{ $errorList[]= "CANNOT MAKE IMAGE IT ALREADY EXISTS"; } } } }else{ $errorList[]= "NO FILE SELECTED"; } if(!$match){ $errorList[]= "File type isn't allowed: $filename"; } if(sizeof($errorList) == 0){ return $fullPath.$newfilename; }else{ $eMessage = array(); for ($x=0; $x<sizeof($errorList); $x++){ $eMessage[] = $errorList[$x]; } return $eMessage; } } when i use ajax to call this, no problem. the 3 pictures upload. when i use a regular call, @imagejpeg returns false..... Link to comment https://forums.phpfreaks.com/topic/238730-imagejpeg-only-works-with-ajax-call/#findComment-1226742 Share on other sites More sharing options...
teynon Posted June 7, 2011 Share Posted June 7, 2011 Please post your code in a CODE tag Like this: [ CODE ] My Code [/ CODE ] without the spaces. Please post your form submission code. Link to comment https://forums.phpfreaks.com/topic/238730-imagejpeg-only-works-with-ajax-call/#findComment-1226743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.