感触life

PHP图片上传,并生成缩略图保存

HTML表单

<form action="upload.php" method="post" enctype="multipart/form-data">
上传:<input type="file" name="filename">
<input type="submit">
</form>

PHP接收处理upload.php

// 文件及缩放尺寸
$imgfile = 'a.jpg';//这可以读取刚上传的文件
$percent = 0.5;//以原图片的长宽的0.1百分比为新的长宽来创建新的图片此图片的标志为$image_p
list($width, $height) = getimagesize($imgfile);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$filename=date("YmdHis").".jpg";//缩略图名字
$path="./upload/";//存放的路径
imagejpeg($thumb,$path.$filename);//保存文件
//imagepng($thumb,"./circle.png");
imagedestroy($thumb);
?>
<img src="<?php echo $path.$filename?>" width="280px" height="202px">

码字很辛苦,转载请注明来自感触life-博客《PHP图片上传,并生成缩略图保存》

评论

  1. admin #1

    😯 😕 😕 😕

    回复
    2016-04-23