<?php
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){
$details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.');
$type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']);
eval('$srcImg = imagecreatefrom'.$type.'("$imageDirectory/$imageName");');
$thumbHeight = $details[1] * ($thumbWidth / $details[0]);
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight,
$details[0], $details[1]);
eval('image'.$type.'($thumbImg, "$thumbDirectory/$imageName"'.
(($type=='jpeg')?', $quality':'').');');
imagedestroy($srcImg);
imagedestroy($thumbImg);
}
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
createThumbnail("/location/of/main/image", $name, "/location/to/store/thumb", 120, 80);
//120 = thumb width :: 80 = thumb quality (1-100)
}
}
?>
<html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>图片上传</title> </head> <body> <h1>文件上传(只允许上传jpg类型图片)</h1> <form enctype="multipart/form-data" action="upload_img.php" method="post"> <input name="upfile" type="file"><br><br> <input type="submit" value="提交"> </form> </body> </html>
<?php
//上传图片保存地址
$uploadfile = "upfiles/".$_FILES['upfile']['name'];
//缩略图保存地址
$smallfile = "upfiles/small_".$_FILES['upfile']['name'];
if($_FILES['upfile']['type'] != "image/jpeg")
{
echo '文件类型错误';
}
else
{
move_uploaded_file($_FILES['upfile']['tmp_name'],$uploadfile); //上传文件
$dstW=200;//缩略图宽
$dstH=200;//缩略图高
$src_image=ImageCreateFromJPEG($uploadfile);
$srcW=ImageSX($src_image); //获得图片宽
$srcH=ImageSY($src_image); //获得图片高
$dst_image=ImageCreateTrueColor($dstW,$dstH);
ImageCopyResized($dst_image,$src_image,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
ImageJpeg($dst_image,$smallfile);
echo '文件上传成功<br>';
echo "<img src='$smallfile' />";
}
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有