Thinkphp3.2簡(jiǎn)單解決多文件上傳只上傳一張的問(wèn)題
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í)例化上傳類(lèi)
$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,上傳后的名稱(chēng)為:59c8d38cdb968.jpg

若是感覺(jué)這種命名不可靠,可采取第二種方法:
$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é)果類(lèi)似于:672563_30ad4d8a2aafc832363de8edc1940b5c59c8d44a303f9.jpg

然,命名可根據(jù)需要自行修改,多文件上傳方法很多,這里只是提供個(gè)簡(jiǎn)單便捷的方法!
以上這篇Thinkphp3.2簡(jiǎn)單解決多文件上傳只上傳一張的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- layui框架實(shí)現(xiàn)文件上傳及TP3.2.3(thinkPHP)對(duì)上傳文件進(jìn)行后臺(tái)處理操作示例
- ThinkPHP結(jié)合AjaxFileUploader實(shí)現(xiàn)無(wú)刷新文件上傳的方法
- Thinkphp多文件上傳實(shí)現(xiàn)方法
- thinkPHP3.2簡(jiǎn)單實(shí)現(xiàn)文件上傳的方法
- thinkphp表單上傳文件并將文件路徑保存到數(shù)據(jù)庫(kù)中
- 封裝ThinkPHP的一個(gè)文件上傳方法實(shí)例
- Thinkphp5 自定義上傳文件名的實(shí)現(xiàn)方法
- ThinkPHP實(shí)現(xiàn)帶驗(yàn)證碼的文件上傳功能實(shí)例
- Thinkphp5+uploadify實(shí)現(xiàn)的文件上傳功能示例
- Thinkphp5框架實(shí)現(xiàn)圖片、音頻和視頻文件的上傳功能詳解
- ThinkPHP5.0多個(gè)文件上傳后找不到臨時(shí)文件的修改方法
- Thinkphp框架+Layui實(shí)現(xiàn)圖片/文件上傳功能分析
相關(guān)文章
Laravel多條件where查詢(xún)語(yǔ)句使用詳解
這篇文章主要為大家介紹了Laravel多條件where查詢(xún)語(yǔ)句使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
淺談php中的訪(fǎng)問(wèn)修飾符private、protected、public的作用范圍
下面小編就為大家?guī)?lái)一篇淺談php中的訪(fǎng)問(wèn)修飾符private、protected、public的作用范圍。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11
PHP設(shè)計(jì)模式之中介者模式(Mediator Pattern)入門(mén)與應(yīng)用案例詳解
這篇文章主要介紹了PHP設(shè)計(jì)模式之中介者模式(Mediator Pattern),結(jié)合實(shí)例形式詳細(xì)分析了PHP中介者模式的基本概念、原理、應(yīng)用案例與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-12-12
vscode運(yùn)行php報(bào)錯(cuò)php?not?found解決辦法
這篇文章主要給大家介紹了關(guān)于vscode運(yùn)行php報(bào)錯(cuò)php?not?found的解決辦法,這個(gè)問(wèn)題可能是由于您的計(jì)算機(jī)上沒(méi)有安裝PHP或者VS?Code沒(méi)有正確配置PHP的路徑所導(dǎo)致的,文中將解決的辦法介紹的很詳細(xì),需要的朋友可以參考下2023-07-07
laravel 5 實(shí)現(xiàn)模板主題功能(續(xù))
前面一篇文章,我們簡(jiǎn)單討論了laravel模板主題功能,本文我們繼續(xù)探討laravel模板主題功能的實(shí)現(xiàn),本次實(shí)現(xiàn)比較重,有興趣慢慢看吧。2015-03-03
Thinkphp5+uploadify實(shí)現(xiàn)的文件上傳功能示例
這篇文章主要介紹了Thinkphp5+uploadify實(shí)現(xiàn)的文件上傳功能,結(jié)合實(shí)例形式分析了Thinkphp5結(jié)合uploadify實(shí)現(xiàn)文件上傳的具體步驟、原理與相關(guān)操作技巧,需要的朋友可以參考下2018-05-05
Laravel5.1 框架模型多態(tài)關(guān)聯(lián)用法實(shí)例分析
這篇文章主要介紹了Laravel5.1 框架模型多態(tài)關(guān)聯(lián)用法,結(jié)合實(shí)例形式分析了laravel5.1框架模型多態(tài)關(guān)聯(lián)具體實(shí)現(xiàn)、使用方法與操作注意事項(xiàng),需要的朋友可以參考下2020-01-01

