php SWFUpload 怎么创建缩略图并且保存到指定文件夹里面

2013 年 5 月 24 日3590

当前位置:主页>网络编程>PHP教程>资讯:php SWFUpload 怎么创建缩略图并且保存到指定文件夹里面

php SWFUpload 怎么创建缩略图并且保存到指定文件夹里面

http://www.zjjv.com/2013-04-01 来源: 站长家园 责任编辑(袁袁) 我要投递新闻

upload.php

<?php

/*

* swfupload图片上传

*/

if (isset($_POST["PHPSESSID"])) {

session_id($_POST["PHPSESSID"]);

}

session_start();

ini_set("html_errors", "0");

if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) ||$_FILES["Filedata"]["error"] != 0) {

echo "错误:无效的上传!";

exit(0);

}

// Get the image and create a thumbnail

$file_types=explode(".",$_FILES["Filedata"]["name"]);

$file_type=$file_types[count($file_types)-1];

if(strtolower($file_type)=='gif' )

{

$img = imagecreatefromgif($_FILES["Filedata"]["tmp_name"]);

}

else if(strtolower($file_type)=='png')

{

$img = imagecreatefrompng($_FILES["Filedata"]["tmp_name"]);

}

else if(strtolower($file_type)=='bmp')

{

$img = imagecreatefromwbmp($_FILES["Filedata"]["tmp_name"]);

}

else

{

$img = imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);

}

if (!$img) {

echo "错误:无法创建图像 ". $_FILES["Filedata"]["tmp_name"];

exit(0);

}

$width = imageSX($img);

$height = imageSY($img);

if (!$width || !$height) {

echo "错误:无效的高或高";

exit(0);

}

// Build the thumbnail

$target_width = 100;

$target_height = 100;

$target_ratio = $target_width / $target_height;

$img_ratio = $width / $height;

if ($target_ratio > $img_ratio) {

$new_height = $target_height;

$new_width = $img_ratio * $target_height;

} else {

$new_height = $target_width / $img_ratio;

$new_width = $target_width;

}

if ($new_height > $target_height) {

$new_height = $target_height;

}

if ($new_width > $target_width) {

$new_height = $target_width;

}

$new_img = ImageCreateTrueColor(100, 100);

if (!@imagefilledrectangle($new_img, 0, 0, $target_width-1, $target_height-1, 0)) { // Fill the image black

echo "错误:不能填充新图片";

exit(0);

}

if (!@imagecopyresampled($new_img, $img, ($target_width-$new_width)/2, ($target_height-$new_height)/2, 0,0, $new_width, $new_height, $width, $height)) {

echo "错误:不能调整大小的图像";

exit(0);

}

if (!isset($_SESSION["file_info"])) {

$_SESSION["file_info"] = array();

}

ob_start();

imagejpeg($new_img);

$imagevariable = ob_get_contents();

ob_end_clean();

$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);

$_SESSION["file_info"][$file_id] = $imagevariable;

echo "FILEID:" . $file_id; // Return the file id to the script

include("upimg.class.php");

if(!empty($_FILES["Filedata"]) and count(explode(",",$_SESSION["upload_tem"]))<5)

{

$folder="upload/images/tem/".date("Y-m-d");

$up = new upimg("$folder","$folder"); //可以写成:$up = new upimg();

$up->autoThumb = TRUE; //可省略

$up->srcDel=TRUE;

$up->thumbWidth = 550; //可省略

$up->thumbHeight = 400; //可省略

$up->maxsize=2014; //上传文件大小单位是kb

$result= $up->upload('Filedata'); // HTML中<input />的name属性值

$_SESSION["upload_tem"]=$_SESSION["upload_tem"].",".$up->thumbPath;

$_SESSION["upload_tem"]=trim($_SESSION["upload_tem"],",");

}

?>

0

上一篇:PHP 动态网站变 静态缓存 加快网站访问速度 下一篇:PHP 按照比例改变图片大小(非生成缩略图)

相关文章列表

评论总数:0 条 [ 查看全部 ] 网友评论

0 0