1. [代码][PHP]代码
//首先 准备 swfupload 包
//前端用户体验页面
SWFUpload Demos - Application Demo
最多上传5张图片
//后台处理页面 upload.php
$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 "ERROR:Could not fill new image";
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 "ERROR:Could not resize image";
exit(0);
}
if (!isset($_SESSION["file_info"])) {
$_SESSION["file_info"] = array();
}
// Use a output buffering to load the image into a variable
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;
//上传图片处理
if(!is_dir("uploadimage"))
{
mkdir("uploadimage");
}
$pre_fix=md5('120ask120');
move_uploaded_file($_FILES["Filedata"]["tmp_name"],trim("./uploadimage/".$pre_fix.$file_id.".jpg"));
/*图片处理结束*/
echo "FILEID:" . $file_id; // Return the file id to the script
?>
Kimi智能助手
超强AI写作助手,一键总结20w字长文,支持批量文档上传,多端同步内容不怕丢失。论文综述、文档速读、脚本小说创作,统统交给Kimi!实时联网搜索,给你最智能清晰的解答。
下载