×

Thinkphp3.2.x 多图上传几个注意点

admin admin 发表于2016-05-19 23:44:46 浏览1562 评论0

抢沙发发表评论

1、<form enctype="multipart/form-data">

2、<form enctype="multipart/form-data">

3、<input type="file" name="upload_pic[]" multiple>

4、$upload->upload(array($_FILES['upload_pic'])); 或 $upload->upload($_FILES); 否则会出现“非法上传对象”

5、上传配置 $config=array('saveName'   =>    array('uniqid','')); 否则会引起重名覆盖

6.可以选择把上传数组转换为单个文件状态,然后进行单个判断上传

if ($_FILES['file']['name']!=''){
                    $covers=$_FILES['cover'];
                    foreach ($covers as $key=>$val){
                    foreach ($val as $m=>$n){
                    $cover[$m][$key]=$n;
                    }
                    }
                    foreach ($cover as $k=>$v){
                    $con['md5']  = md5_file($v['tmp_name']);
                    $con['sha1'] = sha1_file($v['tmp_name']);
                    $con['size'] = $v['size'];
                    $check = D('PublicUpload')->where($con)->find();
                    if (empty($check)){
                    $upload=new \Think\Upload();
                   $info=$upload->upload(array($v));
                   $info=$info[0];
                   
                   $upload_data['type'] = $info["type"];
                   $upload_data['name'] = $info["name"];
                   $upload_data['path'] = '/Uploads/' . $info['savepath'] . $info['savename'];
                   $upload_data['url'] = $info["url"] ? : '';
                   $upload_data['ext'] = $info["ext"];
                   $upload_data['size'] = $info["size"];
                   $upload_data['md5']  = $info['md5'];
                   $upload_data['sha1']  = $info['sha1'];
                   $upload_data['location']  = 'Local';
                   $result = D('PublicUpload')->create($upload_data);
                   $result = D('PublicUpload')->add($result);
                   $c[]=$upload_data['path'];
                    }else{
                    $c[]=$check['path'];
                    }
                    }
                    $_POST['cover']=implode(';',$c);
                    }


分享到:

群贤毕至

访客