TP3.2.2多文件上传,只上传部分文件?
thinkphp吧
全部回复
仅看楼主
level 1
cpmeng 楼主
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>";
}
}
}
}
2014年09月21日 09点09分 1
level 1
cpmeng 楼主
Controller直接copy的开发手册.开发环境Apache+PHP5.4n
错误提示:
[2] call_user_func() expects parameter 1 to be a valid callback, no array or string given F:\WWW\upload\ThinkPHP\Library\Think\Upload.class.php 第 170 行.
进去看发现这么一段
/* 调用回调函数检测文件是否存在 */
$data = call_user_func($this->callback, $file);
if( $this->callback && $data ){
if ( file_exists(*.*.$data[*path*]) ) {
$info[$key] = $data;
continue;
}elseif($this->removeTrash){
call_user_func($this->removeTrash,$data);//删除垃圾据
}
..但是有时候又能全部上传...求完善[蜷]
2014年09月21日 09点09分 2
level 1
可以哇。。。
2015年01月03日 12点01分 3
level 2
推荐chrome 360浏览器 不同浏览器有时候产生的结果不同 这是tp很坑的一面
2015年01月08日 02点01分 4
level 8
我来证明火狐有这个问题,tp3.2.3
2015年10月28日 08点10分 5
level 1
我的也是 火狐 IE 都有
2015年12月29日 06点12分 6
level 1
这个多是因为上传表单设计的有问题,需要确保上传时多个file表单之间的下标是连续的,写成以下这样可以确保上传没有问题。
<input type='file' name='upload[]'/>
<input type='file' name='upload[]'/>
<input type='file' name='upload[]'/>
2016年04月20日 02点04分 8
1