Tuesday, December 27, 2016

How to upload multiple array of images in laravel

Hi

First of all Happy New Year to all of you.

Today we will learn how to upload multiple array of images in laravel.

When we build dynamic view to add images then we put our field name in array. Like below

 <input type="file" name="images[]" accept="image/*" class="input-group">  


For saving these kind of file or images we needed a controller in laravel.

Below is my controller code for uploading files and images:

 <?php  
 namespace App\Http\Controllers;  
 use Validator;  
 use Redirect;  
 use Request;  
 use Session;  
 class FileController extends Controller {  
  public function multiple_upload(Request $request) {  
   // getting all of the images form post data  
   $fileName=$request->file('images');  
   // Making counting of uploaded images  
   $file_count = count($fileName);  
   // $uploadcount = 0;  
   foreach($fileName as $file) {  
    $rules = array('images' => 'required'); //'required|mimes:png,gif,jpeg,txt,pdf,doc': if we want to validate specific extension  
    $validator = Validator::make(array('images'=> $file), $rules);  
    if($validator->fails()){  
     $destinationPath = public_path("/images");  
     $file = $file->getClientOriginalName();  
     $upload_success = $file->move($destinationPath, $file);  
     $uploadcount ++;  
    }  
   }  
   if($uploadcount == $file_count){  
    Session::flash('success', 'Upload successfully');  
    return Redirect::to('your_route_name');  
   }  
   else {  
    return Redirect::to('your_route_name')->withInput()->withErrors($validator);  
   }  
  }  

Thanks.


5 comments:

  1. Are you unable to deal with transaction errors in your Binance account through mobile app? if you don’t know the process, you can always call the team of skilled executives who is always available and users can talk to the team anytime to avail fruitful solutions. Whenever Binance Support Number you are in doubt, you can dial Binance support number and avail facilities from the team to deal with your issues in no time. You can connect with the team to avail solutions immediately.

    ReplyDelete
  2. Are you unable to receive digital currency from another wallet in Blockchain? Has this become a problem and are you daunted by the fact that you might not enjoy a smooth trading? Don’t worry it is not a big issue and can be taken care of by contacting Blockchain support number where you get in touch with experienced professionals who are Blockchain Support NUmber reliable as well as pro-active. They feel happy and privileged to assist you, so contact them to get your issues fixed in no time in flawless manner.

    ReplyDelete
  3. Are you unable to receive digital currency from another wallet in Gemini? Has this become a problem and are you daunted by the fact that you might not enjoy a smooth trading? Don’t worry it is not a big issue and can be taken care of by contacting Gemini support number Gemini Support Number where you get in touch with experienced professionals who are reliable as well as pro-active. They feel happy and privileged to assist you, so contact them to get your issues fixed in no time in flawless manner.

    ReplyDelete
  4. Are you unable to deal with transaction errors in your Libra Coin account through mobile app? if you don’t know the process, you can always call the team of skilled executives who is always available and users can talk to the team anytime to avail fruitful solutions. Libra Support Number Whenever you are in doubt, you can dial Libra support number and avail facilities from the team to deal with your issues in no time. You can connect with the team to avail solutions immediately.

    ReplyDelete
  5. hey... Great work . I feel nice while i reading blog .You are doing well. Keep it up. We will also provide dial Quickbooks Customer Service Number to reach us call to 1-855-756-1077 for instant help.

    ReplyDelete