亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Thinkphp3.2簡(jiǎn)單解決多文件上傳只上傳一張的問題

 更新時(shí)間:2017年09月26日 09:07:05   作者:傳聞中的張先生  
下面小編就為大家?guī)硪黄猅hinkphp3.2簡(jiǎn)單解決多文件上傳只上傳一張的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

html簡(jiǎn)單頁(yè)面:

index.html代碼:

<form action="{:U('index/upload')}" method="post" enctype="multipart/form-data">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 文件上傳:<input type="file" name = "test[]">
 <input type="submit" value = "提交">
</form>

控制器IndexController.class.php代碼:

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
 public function index(){
  $this->display();
 }
 public function upload(){
  if(IS_POST){
   $config = array(
    'maxSize' => 3145728,
    'rootPath' => './Uploads/',
    'savePath' => '',
    'saveName' => array('uniqid', mt_rand(1,999999).'_'.md5(uniqid())),
    'exts'  => array('jpg', 'gif', 'png', 'jpeg'),
    'autoSub' => true,
    'subName' => array('date','Ymd'),
   );
   $upload = new \Think\Upload($config);// 實(shí)例化上傳類
   $info = $upload->upload();
   if(!$info) {
    $this->error($upload->getError());
   }else{
    foreach($info as $file){
     echo $file['savepath'].$file['savename'];
    }
   }
  }else{
   $this->display();
  }
 }
}

上傳結(jié)果顯示:

好多人在進(jìn)行多文件上傳的時(shí)候,最后發(fā)現(xiàn)只是上傳了一張,主要就是命名所致,因?yàn)槭峭瑯拥拿?,所以最后就剩一張圖片
解決方法:第一種:

$config = array(
    'maxSize' => 3145728,
    'rootPath' => './Uploads/',
    'exts'  => array('jpg', 'gif', 'png', 'jpeg'),
    'autoSub' => true,
    'subName' => array('date','Ymd'),
    'saveRule' => '',
   );

置空$config里面的saveRule,上傳后的名稱為:59c8d38cdb968.jpg

若是感覺這種命名不可靠,可采取第二種方法:

$config = array(
    'maxSize' => 3145728,
    'rootPath' => './Uploads/',
    'saveName' => array('uniqid', mt_rand(1,999999).'_'.md5(uniqid())),
    'exts'  => array('jpg', 'gif', 'png', 'jpeg'),
    'autoSub' => true,
    'subName' => array('date','Ymd'),
   );

設(shè)置$config中: 'saveName' => array('uniqid', mt_rand(1,999999).'_'.md5(uniqid())),

其最后的結(jié)果類似于:672563_30ad4d8a2aafc832363de8edc1940b5c59c8d44a303f9.jpg

然,命名可根據(jù)需要自行修改,多文件上傳方法很多,這里只是提供個(gè)簡(jiǎn)單便捷的方法!

以上這篇Thinkphp3.2簡(jiǎn)單解決多文件上傳只上傳一張的問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論