thinkphp3.2.2实现生成多张缩略图的方法_PHP
本文实例讲述了thinkphp3.2.2实现生成多张缩略图的方法。分享给大家供大家参考。
具体实现方法如下:
代码如下:
public function dz_upload() { //上传多张缩略图 上传2张缩略图
if (isset($_FILES['ori_img'])){
$upload = new \Think\UploadFile();// 实例化上传类
$upload->maxSize = 3000000 ;// 设置附件上传大小 C('UPLOAD_SIZE');
//$upload->savePath = './Public/Uploads/' . $path; // 设置附件上传目录
$upload->savePath = './Public/Uploads/' . 'thumb/'; // 设置附件上传目录
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
$upload->saveRule = 'time';
$upload->uploadReplace = true; //是否存在同名文件是否覆盖
$upload->thumb = true; //是否对上传文件进行缩略图处理
$upload->thumbMaxWidth = '100,300'; //缩略图处理宽度
$upload->thumbMaxHeight = '50,150'; //缩略图处理高度
//$upload->thumbPrefix = $prefix; //缩略图前缀
$upload->thumbPrefix = 'm_,s_'; //生产2张缩略图
//$upload->thumbPath = './Public/Uploads/' . $path . date('Ymd', time()) . '/'; //缩略图保存路径
$upload->thumbPath = './Public/Uploads/' . 'thumb/' . date('Ymd', time()) . '/'; //缩略图保存路径
//$upload->thumbRemoveOrigin = true; //上传图片后删除原图片
$upload->thumbRemoveOrigin = false; //上传图片后删除原图片
$upload->autoSub = true; //是否使用子目录保存图片
$upload->subType = 'date'; //子目录保存规则
$upload->dateFormat = 'Ymd'; //子目录保存规则为date时时间格式
if (!$upload->upload()) {// 上传错误提示错误信息
echo json_encode(array('msg' => $this->error($upload->getErrorMsg()), 'status' => 0));
} else {// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
$picname = $info[0]['savename'];
$picname = explode('/', $picname);
//$picname = $picname[0] . '/' . $prefix . $picname[1];
$picname = $picname[0] . '/' . '_hz' . $picname[1];
print_r($picname);
echo json_encode(array('status' => 1, 'msg' => $picname));
}
}
}
调用方法:
代码如下:
$k=A("Index"); // 调用控制器Index 的koo方法 重点(lish)
$slt=$k->dz_upload();
这里要注意thinkphp3.2.2并没有UploadFile,UploadImage 类,需要从扩展包里提取出来再自己加入,把他们放到ThinkPHP\Library\Think目录下.
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article will introduce how to turn off the thumbnail function displayed when the mouse moves the taskbar icon in Win11 system. This feature is turned on by default and displays a thumbnail of the application's current window when the user hovers the mouse pointer over an application icon on the taskbar. However, some users may find this feature less useful or disruptive to their experience and want to turn it off. Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another drawback is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. but

Windows 1122H2 is the first feature update for Windows 11 and should bring a ton of new features and much-needed improvements. One of the improvements is the ability to preview folder thumbnails of files within a folder. If you don't like the look of folder thumbnails in Windows 11, here's how you can change it. A set of custom icons for folder thumbnails in Windows 11 (courtesy of Reddit's LEXX911) that lets you zoom in on previews and change folder icon styles. You still have to deal with individual file previews (in Windows 7, for example, folder thumbnails can display multiple images at the same time), but you can make it larger and more convenient. important hint:

1. First enter Visual Studio Code and click [File] in the upper left corner. 2. Then click [Preferences]. 3. Click the [Settings] item. 4. Then click [Text Editor-Thumbnail]. 5. Finally, in the thumbnail item, turn on [Control whether to display thumbnails].

iFlytek has upgraded the meeting minutes function, which can directly convert spoken expressions into written drafts, and AI can summarize meeting minutes based on recordings. AI can help you complete the writing of meeting minutes. On August 31, the iFlytek web version was upgraded, adding a real-time recording function on the PC side, which can use artificial intelligence to intelligently generate meeting minutes. The launch of this function will greatly improve the efficiency of users in organizing content and following up on key work items after meetings. For people who often attend meetings, this function is undoubtedly a very practical tool that can save a lot of time and energy. The application scenario of this function is mainly to convert recordings on the PC to text and automatically generate meeting minutes, aiming to provide users with the best quality. Products with excellent services and the most advanced technology to quickly improve office efficiency

How to use PHP to generate refreshable image verification codes. With the development of the Internet, in order to prevent malicious attacks and automatic machine operations, many websites use verification codes for user verification. One common type of verification code is the image verification code, which generates a picture containing random characters and requires the user to enter the correct characters before proceeding. This article will introduce how to use PHP to generate refreshable image verification codes and provide specific code examples. Step 1: Create a verification code image First, we need to create a verification code image

Natural language generation is an artificial intelligence technology that converts data into natural language text. In today's big data era, more and more businesses need to visualize or present data to users, and natural language generation is a very effective method. PHP is a very popular server-side scripting language that can be used to develop web applications. This article will briefly introduce how to use PHP for basic natural language generation. Introducing the natural language generation library The function library that comes with PHP does not include the functions required for natural language generation, so

Data visualization is essential for efficient information understanding and presentation. Among the many chart types available, waffle charts are a novel way of displaying data in a grid-like structure with square tiles. The powerful Python module PyWaffle facilitates the development of waffle charts, similar to many computational and data analysis methods. In this article, we will look at how to create a waffle chart using the sophisticated Python module PyWaffle. Let’s install PyWafle and see how to use it to visualize categorical data. Run the following command in your cmd to install the library and then import it into your code. The Chinese translation of pipinstallpywaffleExample1 is: Example 1 In this example, we

With the development of the Internet, pictures have become an indispensable part of web pages. But as the number of images increases, the loading speed of images has become a very important issue. In order to solve this problem, many websites use thumbnails to display images, but in order to generate thumbnails, we need to use professional image processing tools, which is a very troublesome thing for some non-professionals. Then, using JavaScript to achieve automatic thumbnail generation becomes a good choice. How to use JavaS
