thinkPHP3.2.2多文件上传,只上传部分文件?

浏览:5163 发布日期:2014/09/21 分类:求助交流
index.html
<form action="__URL__/upload" enctype="multipart/form-data" method="post" >
<input type="file" name="photo1" />
<input type="file" name="photo2" />
<input type="file" name="photo3" />
<input type="file" name="photo4" />
<input type="file" name="photo5" />
<input type="file" name="photo6" />
<input type="submit" value="submit" >
</form>

IndexController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
echo "IndexController.index()";
$this->display();
}
public function upload(){
$dir = 'Photos';
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = $dir; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 31457280 ;// 设置附件上传大小30M
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath = './Public/Uploads/'; // 设置附件上传目录
// 上传文件
$info = $upload->upload($_FILES);
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息
$upload->getError();
$i=0;
foreach($info as $file){
$i += 1;
echo $i;
echo "-------------->";
echo $file['savepath'].$file['savename'];
echo "<br>";
}
}
}
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>