如题所述
ããThinkphpæåä¸å¯¹äºå¤æ件ä¸ä¼ æè¿°çå¾æ¸
æ¥ï¼å¦æéè¦ä½¿ç¨å¤ä¸ªæ件ï¼åªéè¦ä¿®æ¹è¡¨åï¼æ
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<input type='file' name='photo'>
ããæ¹ä¸º
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<li><input type='file' name='photo1'></li>
ãã<li><input type='file' name='photo2'></li>
ãã<li><input type='file' name='photo3'></li>
ããæè
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ããæä¸èªå·±çä¸ä¼ 表åå为两个ï¼ä¸ä¸ªä¸ä¼ å¾çï¼ä¸ä¸ªä¸ä¼ è§é¢ãå段å为imageãvideoã
ããhtml代ç å¦ä¸
ããå¤å¶ä»£ç 代ç å¦ä¸:
ããå¾ç:<input type="file" name="image[]">
ããè§é¢:<input type="file" name="video[]">
ããmodel代ç ï¼
ããå¤å¶ä»£ç 代ç å¦ä¸:
ããprotected $info= '';
ããprotected $_auto = array(
ããarray('image','upload',3,callback),//èªå¨å®ææ¹æ³
ããarray('video','videoupload',3,callback), //èªå¨å®ææ¹æ³
ãã);//èªå¨å¡«å ä¸ä¼ å¾ççæ缩ç¥å¾
ããprotected function upload(){
ãã$var = $_FILES['image']['name'];
ããimport('ORG.Net.UploadFile');
ãã$upload = new UploadFile();
ãã$upload->saveRule = time;
ãã$upload->allowExts = array('jpg', 'gif', 'png', 'zip','flv');
ãã$upload->thumb = true;
ãã//è§é¢è·¯å¾ãããåªæ¯æflvåç¼ï¼
ãã$upload->videopath = './Public/upload/Video/';
ãã$upload->savePath = './Public/upload/images/';
ãã$upload->thumbPrefix = '250_115_,150_110_,213_156_';
ãã$upload->thumbMaxWidth='250,150,213';
ãã$upload->thumbMaxHeight='115,110,156';
ããif(!in_array('',$var) || !in_array('',$_FILES['video']['name'])){
ããif(!$upload->upload()) {
ããecho $upload->getErrorMsg();die;
ãã}else{
ãã$this->info = $upload->getUploadFileInfo();
ããif(!in_array('',$var) && !in_array('',$_FILES['video']['name'])){
ããreturn $this->info[1]['savename'];
ãã}elseif(!in_array('',$var)){
ããreturn $this->info[0]['savename'];
ãã}else{
ããreturn false;
ãã}
ãã}
ãã}else{
ããreturn flase;
ãã}
ãã}
ãã//ä¸ä¼ è§é¢
ããprotected function videoupload(){
ããif(!in_array('',$var) && !in_array('',$_FILES['video']['name'])){
ããreturn $this->info[0]['savename'];
ãã}elseif(!in_array('',$_FILES['video']['name'])){
ããreturn $this->info[1]['savename'];
ãã}else{
ããreturn false;
ãã}
ãã}
ããæç« æåææ¥åæä¸ä¸å¤æ件ä¸ä¼ åçå§ï¼å æ¥ççhtml代ç
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ããè¿ç§å°±æ¯æ表ååéå®ä¹ä¸ºæ°ç»ï¼å¨phpä¸æ°ç»ç¹æ®åéå®å¯ä»¥åå¨å¤ä¸ªä¸å®é¿çå 容ï¼æ以æ们就å¯ä»¥èªå®å¤æ件ä¸ä¼ æ¡äºï¼é£ä¹å¨phpå¤çæ¶æ们è¦å¦ä½æä½ï¼ä¸é¢çä¾åã
ããå¤å¶ä»£ç 代ç å¦ä¸:
ããprotected $_auto = array(
ããarray('image','upload',3,callback),//èªå¨å®ææ¹æ³
ããarray('video','videoupload',3,callback), //èªå¨å®ææ¹æ³
ãã);//èªå¨å¡«å ä¸ä¼ å¾ççæ缩ç¥å¾
ããè¿ä¸ªæ¯åè¯thinkphpæ¯æ°ç»åéäºï¼å¹¶ä¸éè¦ååçæçphpä¸æ¥å¤æéåæ°ç»é¿åº¦åä¸ä¸ªä¸ªä¸ä¼ ç代ç äºï¼å 为äºthinkphpå·±ç»å好äºã
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<input type='file' name='photo'>
ããæ¹ä¸º
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<li><input type='file' name='photo1'></li>
ãã<li><input type='file' name='photo2'></li>
ãã<li><input type='file' name='photo3'></li>
ããæè
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ããæä¸èªå·±çä¸ä¼ 表åå为两个ï¼ä¸ä¸ªä¸ä¼ å¾çï¼ä¸ä¸ªä¸ä¼ è§é¢ãå段å为imageãvideoã
ããhtml代ç å¦ä¸
ããå¤å¶ä»£ç 代ç å¦ä¸:
ããå¾ç:<input type="file" name="image[]">
ããè§é¢:<input type="file" name="video[]">
ããmodel代ç ï¼
ããå¤å¶ä»£ç 代ç å¦ä¸:
ããprotected $info= '';
ããprotected $_auto = array(
ããarray('image','upload',3,callback),//èªå¨å®ææ¹æ³
ããarray('video','videoupload',3,callback), //èªå¨å®ææ¹æ³
ãã);//èªå¨å¡«å ä¸ä¼ å¾ççæ缩ç¥å¾
ããprotected function upload(){
ãã$var = $_FILES['image']['name'];
ããimport('ORG.Net.UploadFile');
ãã$upload = new UploadFile();
ãã$upload->saveRule = time;
ãã$upload->allowExts = array('jpg', 'gif', 'png', 'zip','flv');
ãã$upload->thumb = true;
ãã//è§é¢è·¯å¾ãããåªæ¯æflvåç¼ï¼
ãã$upload->videopath = './Public/upload/Video/';
ãã$upload->savePath = './Public/upload/images/';
ãã$upload->thumbPrefix = '250_115_,150_110_,213_156_';
ãã$upload->thumbMaxWidth='250,150,213';
ãã$upload->thumbMaxHeight='115,110,156';
ããif(!in_array('',$var) || !in_array('',$_FILES['video']['name'])){
ããif(!$upload->upload()) {
ããecho $upload->getErrorMsg();die;
ãã}else{
ãã$this->info = $upload->getUploadFileInfo();
ããif(!in_array('',$var) && !in_array('',$_FILES['video']['name'])){
ããreturn $this->info[1]['savename'];
ãã}elseif(!in_array('',$var)){
ããreturn $this->info[0]['savename'];
ãã}else{
ããreturn false;
ãã}
ãã}
ãã}else{
ããreturn flase;
ãã}
ãã}
ãã//ä¸ä¼ è§é¢
ããprotected function videoupload(){
ããif(!in_array('',$var) && !in_array('',$_FILES['video']['name'])){
ããreturn $this->info[0]['savename'];
ãã}elseif(!in_array('',$_FILES['video']['name'])){
ããreturn $this->info[1]['savename'];
ãã}else{
ããreturn false;
ãã}
ãã}
ããæç« æåææ¥åæä¸ä¸å¤æ件ä¸ä¼ åçå§ï¼å æ¥ççhtml代ç
ããå¤å¶ä»£ç 代ç å¦ä¸:
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ãã<li><input type='file' name='photo[]'></li>
ããè¿ç§å°±æ¯æ表ååéå®ä¹ä¸ºæ°ç»ï¼å¨phpä¸æ°ç»ç¹æ®åéå®å¯ä»¥åå¨å¤ä¸ªä¸å®é¿çå 容ï¼æ以æ们就å¯ä»¥èªå®å¤æ件ä¸ä¼ æ¡äºï¼é£ä¹å¨phpå¤çæ¶æ们è¦å¦ä½æä½ï¼ä¸é¢çä¾åã
ããå¤å¶ä»£ç 代ç å¦ä¸:
ããprotected $_auto = array(
ããarray('image','upload',3,callback),//èªå¨å®ææ¹æ³
ããarray('video','videoupload',3,callback), //èªå¨å®ææ¹æ³
ãã);//èªå¨å¡«å ä¸ä¼ å¾ççæ缩ç¥å¾
ããè¿ä¸ªæ¯åè¯thinkphpæ¯æ°ç»åéäºï¼å¹¶ä¸éè¦ååçæçphpä¸æ¥å¤æéåæ°ç»é¿åº¦åä¸ä¸ªä¸ªä¸ä¼ ç代ç äºï¼å 为äºthinkphpå·±ç»å好äºã
温馨提示:答案为网友推荐,仅供参考