一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP支持多種格式圖片上傳(支持jpg、png、gif)

此處一次支持上傳2個圖片,上傳后生成原圖和質(zhì)量較差的圖,原圖用于保存質(zhì)量高的圖片,質(zhì)量差的圖用于網(wǎng)頁顯示。
php Code
復(fù)制代碼 代碼如下:
<?php
include_once("db.php");
include_once("dbinfo.php");
$connector = new nmdb($host, $username, $password);
$connector -> select_db($database);
$work_group = check_input($_POST['work_group']);
$name = check_input($_POST['name']);
$tel = check_input($_POST['tel']);
$id_card = check_input($_POST['id_card']);
$work_name = check_input($_POST['work_name']);
$place = check_input($_POST['place']);
$work1 = check_input($_POST['work1']);
date_default_timezone_set('PRC');
$date = date("Y-m-d H:i:s");
$quality = 100;
$quality2 = 70;
$quality_png = 9;
$quality2_png = 7;
if(isset($_FILES['work1']) && $_FILES['work1']['error']==0)
{
$size = getimagesize($_FILES['work1']['tmp_name']);
$original = $_FILES['work1']['tmp_name'];
$type = $_FILES['work1']['type'];
//echo $type;
$target_name = date('YmdHis').'_'.preg_replace('`[^a-z0-9-_.]`i','',$_FILES['work1']['name']);
$work1 = $target_name;
$target = dirname(__FILE__).'/uploads/'.$target_name;
switch($type)
{
case "image/jpeg":
$resultImage = imagecreatefromjpeg($original);
imagejpeg($resultImage, $target, $quality);
break;
case "image/png":
$resultImage = imagecreatefrompng($original);
imagepng($resultImage, $target, $quality_png);
break;
case "image/gif":
$resultImage = imagecreatefromgif($original);
imagegif($resultImage, $target, $quality);
break;
default :
die("不支持此文件類型");
exit;
}
$work1_small = $target_name;
$target = dirname(__FILE__).'/uploads/small/'.$target_name;
switch($type)
{
case "image/jpeg":
$resultImage = imagecreatefromjpeg($original);
imagejpeg($resultImage, $target, $quality2);
break;
case "image/png":
$resultImage = imagecreatefrompng($original);
imagepng($resultImage, $target, $quality2_png);
break;
case "image/gif":
$resultImage = imagecreatefromgif($original);
imagegif($resultImage, $target, $quality2);
break;
default :
die("不支持此文件類型");
exit;
}
}
if(isset($_FILES['work2']) && $_FILES['work2']['error']==0)
{
$size = getimagesize($_FILES['work2']['tmp_name']);
$original = $_FILES['work2']['tmp_name'];
$type = $_FILES['work2']['type'];
$target_name = date('YmdHis').'_'.preg_replace('`[^a-z0-9-_.]`i','',$_FILES['work2']['name']);
$work2 = $target_name;
$target = dirname(__FILE__).'/uploads/'.$target_name;
switch($type)
{
case "image/jpeg":
$resultImage = imagecreatefromjpeg($original);
imagejpeg($resultImage, $target, $quality);
break;
case "image/png":
$resultImage = imagecreatefrompng($original);
imagepng($resultImage, $target, $quality_png);
break;
case "image/gif":
$resultImage = imagecreatefromgif($original);
imagegif($resultImage, $target, $quality);
break;
default :
die("不支持此文件類型");
exit;
}
$work2_small = $target_name;
$target = dirname(__FILE__).'/uploads/small/'.$target_name;
switch($type)
{
case "image/jpeg":
$resultImage = imagecreatefromjpeg($original);
imagejpeg($resultImage, $target, $quality2);
break;
case "image/png":
$resultImage = imagecreatefrompng($original);
imagepng($resultImage, $target, $quality2_png);
break;
case "image/gif":
$resultImage = imagecreatefromgif($original);
imagegif($resultImage, $target, $quality2);
break;
default :
die("不支持此文件類型");
exit;
}
}
$sql="insert into photo(work_group,name,tel,id_card,work_name,place,work,work_small,date) values('$work_group','$name','$tel','$id_card','$work_name','$place','$work1','$work1_small','$date')";
//echo $sql;
$result = $connector -> query($sql) or die(mysql_error());
if($work2 != "" && $work2_small != null)
{
$sql2="insert into photo(work_group,name,tel,id_card,work_name,place,work,work_small,date) values('$work_group','$name','$tel','$id_card','$work_name','$place','$work2','$work2_small','$date')";
$result2 = $connector -> query($sql2) or die(mysql_error());
}
$connector -> close($connector);
$page="../upload.php";
echo "<script>alert('上傳成功!'); window.location = \"".$page."\";</script>";
?>

有些問題需要說明下:
JPEG圖像生成的圖像的質(zhì)量的是一個范圍從0(最低質(zhì)量,最小的文件大小)到100(最高質(zhì)量,最大文件大小)。而ImagePNG生成圖像的質(zhì)量范圍從0到9的,傳入的這個范圍以外的參數(shù)則該函數(shù)不會工作。
判斷上傳文件的類型,$type = $_FILES['work1']['type'];。
創(chuàng)建各種格式的圖片可以使用這些函數(shù):imagecreatefromjpeg()、imagecreatefrompng()、imagecreatefromgif()。

php技術(shù)PHP支持多種格式圖片上傳(支持jpg、png、gif),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 成人国产亚洲 | 免费永久在线观看污污的网站 | 亚洲综合图片人成综合网 | 国产人成激情视频在线观看 | 精品一区二区三区波多野结衣 | www.91在线播放 | 黄色激情视频网址 | 成人宗合网 | 四虎在线精品免费高清在线 | 亚洲视频一区二区三区四区 | 综合成人 | 视频在线观看一区二区 | 2021在线永久免费视频 | www.夜夜操| 亚洲国产第一 | 亚洲国产精品第一页 | 91精品啪在线看国产网站 | 国产网红在线 | 亚洲吊丝网 | 国产精品亚洲国产三区 | 高清视频一区二区三区 | 91精品宅男在线观看 | 福利国产| 亚洲国产婷婷香蕉久久久久久 | 丁香婷婷综合五月综合色啪 | 一个色亚洲| 色yeye成人免费视频 | 国产日韩欧美一区二区三区综合 | 国产成人综合久久亚洲精品 | 国产精品国产自线拍手机观看 | 国产美妇 | 特黄aaaaa日本大片免费看 | 五月婷婷激情六月 | 国产午夜在线观看 | 精品视频在线免费观看 | 国产精品人人视频 | 在线播放一区二区三区 | 黄色小视频在线播放 | 中文字幕亚洲一区二区三区 | 亚洲综合插插 | 激情丁香网 |