新发布的3.2版本上传图片没有带缩略图功能,我改了下代码,可以生成缩略图
新发布的3.2版本上传图片没有带缩略图功能,我改了下代码,可以生成缩略图。现在附上代码和说明
把这2个类放在hinkPHP\Library\Think\下
UploadFile.class.php
UploadImage.class.php
添加新闻的代码如下
public function add(){
if(IS_POST){
//获取表单元素,这里可以改的
$data ['title'] = I('post.title','','htmlspecialchars');
$data['author'] = I('post.author','','htmlspecialchars');
$data['content'] = I('post.content','','htmlspecialchars');
$data['inputtime'] = time();
$data['tid'] = I('post.tid','0');
$data['status'] =1;
if (isset($_FILES['pic'])){
//文件上传配置,可以生成缩略图
$date11 =date('Y-m-d');
$upload = new \Think\UploadFile();// 实例化上传类
$upload->maxSize = 3000000 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->allowTypes = array('image/jpg','image/jpeg','image/pjpeg','image/png','image/gif');
$upload->savePath = './Public/Uploads/News/'.$date11.'/';// 设置附件上传目录
$upload->saveRule = 'uniqid';
//缩略图配置
$upload->thumb = true;
$upload->thumbMaxWidth = '440';
$upload->thumbMaxHeight = '580';
$upload->thumbPrefix = 's_';
$upload->thumbRemoveOrigin = false;
//开始上传
if($upload->upload()){
$info = $upload->getUploadFileInfo();
//大图
$data['newspic'] = '/Public/Uploads/News/'.$date11.'/'.$info[0]['savename'];
}
}
//入库操作
}else{
$this->display();
}
}
上传图片生成缩略图.rar
( 8.44 KB 下载:609 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools
