ThinkPHP学习札记(十四)上传文件
ThinkPHP学习笔记(十四)上传文件
需要进行Action的设置,包括UploadFile的文件引入
<?php /** * 处理文件上传功能 * @author admin * * 上传多文件时; * 可以在input中个的name中后加入[];例如:file[] * 或者可以设置标示:file1,file2 * * 只有在插入数据库的时候才需要进行循环插入 */class FileAction extends Action{ public function index(){ $file=M('file'); $list=$file->select(); $this->assign('alist',$list); $this->display(); } function upload(){ //经过自定义模型 if (empty($_FILES)){ $this->error("必须选择上传文件"); }else { $msg = $this->up(); if (isset($msg)){ $result=$this->insertDb($msg); if ($result){ $this->success('上传成功'); }else{ $this->error('保存出错了那'); } }else{ $this->error($msg); } } } private function insertDb($data){ $file=M('file'); $result=true; for ($i = 0; $i data($data)->add()){ return false; } } return true; } private function up(){ import('ORG.Net.UploadFile'); $upload=new UploadFile(); $upload->maxSize='1000000';//大小:-1不限制;单位是bytes $upload->savePath='./Public/';//上传路径:建议以主路口或者平级目录的子目录来 $upload->saveRule='uniqid';//保存规则:默认是uniqid $upload->hashType='MD5';//hash验证方法,默认是md5 $upload->autoCheck=false; $upload->uploadReplace=true; $upload->allowExts=array('jpg','png');//允许上传的文件格式 $upload->allowTypes=array('image/png','image/jpg');//文件的mime类型 $upload->thumb=true;//是否开启图片文件缩略图 $upload->thumbMaxWidth='100,500';//可以用,分割,写多个最大宽度 $upload->thumbMaxHeight='100,500';//与width一一对应 $upload->thumbPrefix='s_,m_';//缩略图文件前缀,与width一一对应// $upload->thumbPath='';//缩略图的保存路径,如果为空直接上传至$upload->savePath// $upload->thumbFile='';//缩略图的文件名,一般不会用,直接用前缀就可以了 $upload->thumbRemoveOrigin=1;//生成新图后是否删除原图 // $upload->autoSub=false;//是否使用子目录进行保存// $upload->subType='';//子目录创建方式,默认为hash创建,也可以设置为date// $upload->dateFormat='';//子目录date方式的指定格式// $upload->hashLevel='';//hash的层级 if ($upload->upload()) { $msg=$upload->getUploadFileInfo(); dump($msg); return $msg; }else { $this->error($upload->getErrorMsg()); return $upload->getErrorMsg(); } }}?>
html
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title><!--{$title}--></title><volist name="alist" id="vo"> <img src="/static/imghw/default1.png" data-src="__PUBLIC__/s_<!--{$vo['filename']}-- alt="ThinkPHP学习札记(十四)上传文件" >" class="lazy" filename>"/> <img src="/static/imghw/default1.png" data-src="__PUBLIC__/m_<!--{$vo['filename']}-- alt="ThinkPHP学习札记(十四)上传文件" >" class="lazy" filename>"/></volist>

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



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Use java's File.getParentFile() function to get the parent directory of a file. In Java programming, we often need to operate files and folders. When we need to get the parent directory of a file, we can use the File.getParentFile() function provided by Java. This article explains how to use this function and provides code examples. File class in Java is the main class used to operate files and folders. It provides many methods to obtain and manipulate file properties

Use java's File.getParent() function to get the parent path of a file. In Java programming, we often need to operate files and folders. Sometimes, we need to get the parent path of a file, which is the path of the folder where the file is located. Java's File class provides the getParent() method to obtain the parent path of a file or folder. The File class is Java's abstract representation of files and folders. It provides a series of methods for operating files and folders. Among them, get
