Alright I got this script that uploads and resizes an image. it works fine on my local server but when I uploaded it to a remote server the imagejpeg() returns false.
$img = checkImage($_FILES['pic']);
if($img['error']==FALSE){
$imgr = imageResample($_FILES['pic']['tmp_name'],$_FILES['pic']['type']);
$image = "images/".$id.$img['type'];
$to = $_SERVER['DOCUMENT_ROOT']."/KBD/".$image;
if(imagejpeg($imgr,$to,100)){
echo "Image uploaded\n";
$fields_to_change[$i]= "Image";
$values_to_change[$i]= addSlash($image);
$i++;
}
else{
echo "<div class='error'>Image upload failed</div><br>";
}
}
else{
echo "<div class='error'>",$img['error'],"<br></div>";
}
and here are the functions that it calls
function checkImage($image){
$i = array('error'=>FALSE,'ext'=>'');
if($image['name']=="" || $image['name']==NULL) $i['error']="no Image name supplied\n";
if($image['size']>2000000)$i['error']="Image is too big\n";
$type=NULL;
switch($image['type']){
case 'image/gif':
$type = '.gif';
break;
case 'image/png':
$type = '.png';
break;
case 'image/jpeg':
$type = '.jpg';
break;
case 'image/bmp':
$type = '.bmp';
break;
default:
$i['error']= "File type not supported";
break;
}
$i['ext']=$type;
return $i;
}
function imageResample($img,$type){
list($width, $height) = getimagesize($img);
$ratio = 250/($width+$height);
$nheight = $height * $ratio;
$nwidth = $width * $ratio;
$image_p = imagecreatetruecolor($nwidth, $nheight);
switch($type){
case 'image/gif':
$image = imagecreatefromgif($img);
break;
case 'image/png':
$image = imagecreatefrompng($img);
break;
case 'image/jpeg':
$image = imagecreatefromjpeg($img);
break;
case 'image/bmp':
$image = imagecreatefromwbmp($img);
break;
default:
return FALSE;
break;
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0,$nwidth,$nheight, $width, $height);
return $image_p;
}
and to reiterate it all works on my local server. I checked the gd library version and there both the same(version 2.something) thanks in advance