In my site i'm use this function, modify for your enviroment and use. Hope i'm help you. Sorry for poor English.
$tmp_file_name = $userfile;
function post_picture($act) {
global $main_app;
global $tmp_file_name;
global $system_vars;
$im = @imagecreatefromjpeg($tmp_file_name);
if( !$im ) {
$im = @imagecreatefrompng($tmp_file_name);
$img_link = $system_vars[pic_path]."catalog/".$get_vars[firm_id]."/".$get_vars[item_id].".png";
$is_png = true;
} else {
$img_link = $system_vars[pic_path]."catalog/".$get_vars[firm_id]."/".$get_vars[item_id].".jpeg";
$is_png = false;
}
unlink($tmp_file_name);
if( !$im ) {
include($system_vars[hpx_path]."admin_top.hpx");
include($system_vars[hpx_path]."article_pic_error.hpx");
include($system_vars[hpx_path]."admin_bot.hpx");
unlink($img_link);
return;
}
if( !$is_png ) {
$http_img_link = "catalog/".$get_vars[firm_id]."/".$get_vars[item_id].".jpeg";
} else {
$http_img_link = "catalog/".$get_vars[firm_id]."/".$get_vars[item_id].".png";
}
$width = imagesx($im);
$height = imagesy($im);
if( $width>=$height ) {
if( $width>200 ) {
$width = 200;
$height = floor(200/imagesx($im)*$height);
}
} else {
if( $height>150 ) {
$height = 150;
$width = floor(150/imagesy($im)*$width);
}
}
$new_im = imagecreate($width,$height);
imagecopyresized($new_im,$im,0,0,0,0,$width,$height,imagesx($im),imagesy($im));
if( !$is_png ) {
if( !(imagejpeg($new_im,$img_link,80)) ) {
include($system_vars[hpx_path]."admin_top.hpx");
include($system_vars[hpx_path]."system_error.hpx");
include($system_vars[hpx_path]."admin_bot.hpx");
unlink($img_link);
return;
}
} else {
if( !(imagepng($new_im,$img_link)) ) {
include($system_vars[hpx_path]."admin_top.hpx");
include($system_vars[hpx_path]."system_error.hpx");
include($system_vars[hpx_path]."admin_bot.hpx");
unlink($img_link);
return;
}
}
Header("Location: ".$main_app->get_url()."\n");
break;
}