2015-12-28 34 views
0

這裏我需要做的是避免額外的逗號分隔符,同時上傳圖片。在上傳文件時需要多一個圖片。我使用逗號分隔符進行連接。多重上傳時插入額外的逗號如何避免這種情況

控制器

  $filename_new_get = ""; 
      $count = Input::get('count'); 
      for($i = 0 ; $i < $count ; $i++) 

     { 

      $file_more = Input::file('file_more'.$i); 

      $file_more_name = $file_more->getClientOriginalName(); 

      $move_more_img = explode('.',$file_more_name); 

      $filename_new =   $move_more_img[0].str_random(8).".".$move_more_img[1]; 

      $newdestinationPath = '../assets/categoryimage/'; 

      $uploadSuccess_new =Input::file('file_more'.$i)->move($newdestinationPath,$filename_new); 
      $filename_new_get .= $filename_new.","; 

     } 


    $inputs = Input::all(); 

     $file = Input::file('file'); 

     $filename = $file->getClientOriginalName(); 

     $move_img = explode('.',$filename); 

     $filename = $move_img[0].str_random(8).".".$move_img[1]; 

     $destinationPath = '../assets/categoryimage/'; 

     $uploadSuccess = Input::file('file')->move($destinationPath,$filename); 

     $file_name_insert = $filename . ",".$filename_new_get; 
     $data=array(
       'new_category_image'=> $file_name_insert, 
       ); 

查看

<div class="col-lg-8" id="img_upload"> 
        <input type="file" id="file0" name="file" style="background:none;width:185px;border:none;">no files 
        <div id="divTxt"></div> 
      <p><a onClick="addproductimageFormField(); return false;" style="cursor:pointer;color:#F60;width:84px;" id="add_img_btn" >Add</a></p> 
        <input type="hidden" id="aid" value="1"> 
        <input type="text" id="count" name="count" value="0"> 
       </div> 

回答

0

使用此:

$newFileName = rtrim($file_name_insert, ','); 

rtrim將刪除最後沒人要,從連接字符串。

+0

感謝它的工作 – ilakkiya

相關問題