thinkphp 檔案上傳,

來源:互聯網
上載者:User

thinkphp 檔案上傳,

問題描述:

通過表單實現多檔案上傳

html代碼:

<form name="vote" method="post" action="__URL__/add_vote"  enctype="multipart/form-data"><lable><h1>投票名稱 <input name="votename" type="text" /></h1> </lable> <table ><td><tr>選項</tr><tr><input name= 'option' type='text' /></tr></td><td><tr>性別</tr><tr><input name='sex[]' type='text' /></tr></td><td ><tr>學院</tr><tr><input name='school[]' type='text' /></tr></td><td><tr>頭像</tr><tr><input name='thumb[]' type='file' /></tr></td></table><table ><td><tr>選項</tr><tr><input name= 'option' type='text' /></tr></td><td><tr>性別</tr><tr><input name='sex[]' type='text' /></tr></td><td ><tr>學院</tr><tr><input name='school[]' type='text' /></tr></td><td><tr>頭像</tr><tr><input name='thumb[]' type='file' /></tr></td></table>  <input id="" type="submit" value="提交" /></tr></div></form>
後台php 代碼:

public function add_vote(){        var_dump($_POST);        $rowNub = $_POST['row'];        $thumbs=$_POST['thumb'];        $sexes=$_POST['sex'];        $schools=$_POST['school'];        $options=$_POST['option'] ;         $config = array(    //上傳檔案參數            'maxSize'    =>    3145728,                'savePath'   =>   './Public/Uploads/',  //檔案儲存路徑              'saveName'   =>    '',    //檔案命名規則,這裡按原檔案名稱儲存            'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),    //上傳檔案格式            'autoSub'    =>    true,                'subName'    =>    array('date','Ymd'),);//以時間自動命名檔案夾       $upload = new \Think\Upload($config);// 執行個體化上傳類              // 上傳檔案        $info   =   $upload->upload($_FILES);//$_FILES 所有上傳的檔案都會在這個數組裡             if(!$info)        {       // 上傳錯誤提示錯誤資訊           $this->error($upload->getError());       }else       {// 上傳成功 擷取上傳檔案資訊            foreach($info as $file)        {                    echo $file['savepath'].$file['savename'];            }     }    }


檔案目錄結構,手動建立Uploads檔案夾



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.