


Thinkphp3.2 solves the problem of uploading only one file when uploading multiple files
html Simple page:
index.html Code:
##
<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>Controller IndexController.class.php Code:
<?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);// 实例化上传类 $info = $upload->upload(); if(!$info) { $this->error($upload->getError()); }else{ foreach($info as $file){ echo $file['savepath'].$file['savename']; } } }else{ $this->display(); } } }The upload result shows:
Solution: The first one:
##
$config = array( 'maxSize' => 3145728, 'rootPath' => './Uploads/', 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => true, 'subName' => array('date','Ymd'), 'saveRule' => '', );
Leave the saveRule in $config blank, and the name after uploading is: 59c8d38cdb968.jpg
If you feel that this naming is unreliable, you can adopt the second method:
$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'), );
Set in $config: 'saveName' => array('uniqid', mt_rand(1,999999).'_'.md5(uniqid()) ),The final result is similar to: 672563_30ad4d8a2aafc832363de8edc1940b5c59c8d44a303f9.jpg
##Of course, the naming can be modified as needed. There are many ways to upload multiple files, here is just a simple one Convenient method!
The above is the detailed content of Thinkphp3.2 solves the problem of uploading only one file when uploading multiple files. For more information, please follow other related articles on the PHP Chinese website!

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)
