上传类的使用很简单,如果是第一次使用上传功能的朋友需要注意的是html提交表单中的表单属性要加上 enctype属性,如:
复制代码 代码如下:
ThinkPHP的UploadFile类在文件../ThinkPHP/Extend/Library/ORG/Net/UploadFile.class.php中:
复制代码 代码如下:
//引入UploadFile类
import('ORG.Net.UploadFile');
//实例化UploadFile类
$upload = new UploadFile();
//设置文件大小
$upload -> maxSize = 3292200;
//设置文件保存规则唯一
$upload->saveRule = 'uniqid';
//设置上传文件的格式
$upload -> allowExts = array('jpg','png','jpeg');
//保存路径
$upload->savePath ='./Public/Uploads/';
//设置需要生成缩略图,仅对图像文件有效
$upload->thumb = true;
//设置需要生成缩略图的文件前缀
$upload->thumbPrefix = 'm_'; //生产缩略图也可以根据需要生成1张或多张,2张:'m_,s_'
//设置缩略图最大宽度
$upload->thumbMaxWidth = '150';//2张的不同设置:'150,200'
//设置缩略图最大高度
$upload->thumbMaxHeight = '200';
//删除原图
$upload->thumbRemoveOrigin = true;
//上传失败返回错误信息
if(!$upload->upload()){
$this->error($upload->getErrorMsg());
}else{
$this->success('上传成功');
//获取上传文件的信息
$inf= $upload->getUploadFileInfo();
}
经过设置后就能轻松地上传文件,同时,$upload的getUploadFileInfo可以获取上传的文件的信息。

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment