您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
thinkphp3.2.1学习笔记-文件上传
发布时间:2017-09-19 11:46:50编辑:雪饮阅读()
前端表单-单文件上传:
<form method="post" action="__CONTROLLER__/upload" enctype="multipart/form-data">
<input type="file" name="photo" /><br/>
<input type="submit" value="上传">
</form>
前端表单-多文件上传:
<form method="post" action="__CONTROLLER__/upload" enctype="multipart/form-data">
<input type="file" name="photo[]" /><br/>
<input type="file" name="photo[]" /><br/>
<input type="file" name="photo[]" /><br/>
<input type="submit" value="上传">
</form>
文件上传:
//实例化上传类
$upload=new Upload();
$upload->maxSize=3145728;
$upload->exts=array('jpg','jpeg','gif','png');
//这里的相对路径是相对于/Uploads
$upload->savePath='./';
$info=$upload->upload();
if(!$info){ $this->error($upload->getError());}
else{$this->success("上传成功");}
文件上传:
$config=array(
'maxSize'=>3145728,
'exts'=>array('jpg','jpeg','gif','png'),
'savePath'=>'./',
);
//实例化上传类
$upload=new Upload($config);
$info=$upload->upload();
if(!$info){$this->error($upload->getError());}
else{$this->success("上传成功");}
设置文件上传后的存储文件名:
$upload->saveName='123';
设置文件上传重复文件名允许覆盖:
$upload->replace=true;
设置文件上传不建立子目录:
默认情况下会将你上传的文件分组到上传时间所属的日期形如2017-09-17的文件夹中。
$upload->autoSub=false;
设置文件上传子目录名:
$upload->subName='abc';
自行设置文件上传子目录名的日期命名格式:
$upload->subName=array('date','Ymd');
设置文件上传子目录名为函数返回值:
函数来源于应用目录中Common->Common->function.php
$upload->subName='get_user_id';
关闭文件上传的hash设置:
默认是开启的,当开启的时候文件上传后可以在文件信息数组中找到md5值和sha1值。
hash的作用:文件的唯一性验证,你看系统镜像的发布就知道了,查hash值可知道文件是否被篡改过,而文件上传的hash可以作为判断以后上传了同样一张图片的话,就不保存了,直接返回文件的地址引用
$upload->hash=false;
关键字词:thinkphp3.2.1,文件上传