代码如下:
//用ftp上传图片
{if(empty($upfile))
echo "Notice:no picture file has uploaded";
else
{
$result=mysql_query("select goods_id from goods where goods_code='$code'");
$record=mysql_fetch_object($result);
$goodsid=$record->goods_id;
$ext=extend($upfile_name);
$primary_name=substr($upfile_name,0,strlen($upfile_name)-strlen($ext));
$filename=$upfile_name;
mysql_query("update goods set imgname='$filename' where goods_id=$goodsid");
$conn=ftp_connect($server);
$ftp_con=ftp_login($conn,$ftp_name,$ftp_pass);
ftp_chdir($conn,$upload_dir);
$res_code=ftp_put($conn, $filename, $upfile, FTP_BINARY);
if($res_code==1)
echo "Picture has uploaded successfully";
else
echo "Picture has uploaded failer";
//生成缩略图
if(empty($upfile)){
print("No file was transfered!\n无
文件上传!");
exit;
}
$image_path=$upfile;
$small_filename="$primary_name"."_small"."$ext";
$small_filename="C:\Accounts\redbluet\wwwRoot\system\goodspic\\".$small_filename;
@$image_info=getimagesize($image_path);
if($image_info[2]==2)
{@$image2=imagecreatefromjpeg($image_path);
}
else if($image_info[2]==1){
@$image2=imagecreatefromgif($image_path);
}
else{print("不接受的图片!");exit;}
if(empty($image2)){print("系统错误,请重试");exit;}
$image2_x=imagesx($image2);
$image2_y=imagesy($image2);
if($image2_x==$image2_y){
$x=260;
$y=0;
}
else if($image2_x>$image2_y){
$x=260;
$y=intval(260*$image2_y/$image2_x);
}
else{
$y=260;
$x=intval(260*$image2_x/$image2_y);
}
$image1=imagecreate($x,$y);
imagecopyresized($image1,$image2,0,0,0,0,$x,$y,$image2_x,$image2_y);
imagejpeg($image1,"$small_filename");
}
}
posted on 2007-11-18 17:27
技术是第一生产力 阅读(331)
评论(0) 编辑 收藏 引用 所属分类:
PHP技巧