您好,欢迎访问一九零五行业门户网

一个完整的PHP图片上传,生成缩略图,插入数据库代码流程_PHP教程

下面是php编写上传图片同时生成缩略图和插入数据库的一个完代码。
;
exit;
}
$filename = date(ymdhis).substr(microtime(),2,5)...$fileextname;
$picturedir = substr(pathinfo($_server[scrīpt_filename],pathinfo_dirname),0,strlen(pathinfo($_server[scrīpt_filename],pathinfo_dirname))-8);
$uploadurl = $picturedir./.$picturefolder.$filename;
$thumbsurl = $picturedir./.$thumbsfolder.$filename;
if (!move_uploaded_file($_files[url][tmp_name], $uploadurl)){
    echo ;
echo alert(上传失败,图片大小不能超过 $max_file_size kb。);;
echo location=../uploadpicture.php?albumid=$albumid;;
echo īpt>;
exit;
}
list($realwidth, $realheight) = getimagesize($uploadurl);
if($realwidth $percent = 1;
} else {
$percent = $maxthumbwidth / $realwidth;
}
$newwidth = $realwidth * $percent;
$newheight = $realheight * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
list($width, $height, $picturetype, $attrib) = getimagesize($uploadurl);
switch($picturetype)
{
   case 1: $source = imagecreatefromgif($uploadurl); break;
   case 2: $source = imagecreatefromjpeg($uploadurl); break;
   case 3: $source = imagecreatefrompng($uploadurl); break;
}
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $realwidth, $realheight);
switch($picturetype)
{
   case 1: imagegif($thumb, $thumbsurl); break;
   case 2: imagejpeg($thumb, $thumbsurl); break;
   case 3: imagepng($thumb, $thumbsurl); break;
}
$newpicture_sql = insert into pictures (flag,title,url,descrīption,uploadtime,updatetime,isvisible,iscommend) values ($albumid,$title,$filename,$descrīption,$uploadtime,$uploadtime,$isvisible,$iscommend);;
$setcover = update pictures set url = $filename where id = $albumid;;
$totalpictures_sql = select * from pictures where flag = $albumid;;
$totalpictures = mysql_query($totalpictures_sql, $hesweb) or die(mysql_error());
$totalrows_totalpictures = mysql_num_rows($totalpictures);
$newpicture = mysql_query($newpicture_sql, $hesweb) or die(mysql_error());
$pictureid = mysql_insert_id($hesweb);
$coverflag = update pictures set iscover = 1 where id = $pictureid;;
if($totalrows_totalpictures      $cover = mysql_query($setcover, $hesweb) or die(mysql_error());
$flag = mysql_query($coverflag, $hesweb) or die(mysql_error());
}
if($coverflag){
    echo ;
echo alert(上传成功。);;
echo location=../uploadpicture.php?albumid=$albumid;;
echo īpt>;
}
?>
看啦上面的代码希望大家能有所收获。
http://www.bkjia.com/phpjc/486180.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/486180.htmltecharticle下面是php编写上传图片同时生成缩略图和插入数据库的一个完代码。 ?php $title = $_post[title]; $descrīption = $_post[descrīption]; $albumid = $_post[albu...
其它类似信息

推荐信息