php - (laravel) The Excel-sheet is uploaded empty -


i don't know why excel sheet uploaded empty thats controller function

public function uploadedcars(request $request) {      if (!$request->hasfile('file'))         return response::json(['error' => 'no file sent.']);      if (!$request->file('file')->isvalid())         return response::json(['error' => 'file not valid']);      $file = $request->file('file');     $extension = $file->getclientoriginalextension();       if ($extension == "csv" || $extension == "csv" || $extension == "xlsx" || $extension == "xlsx"         || $extension == "rtf" || $extension == "rtf" ||  $extension == "ods" ||  $extension =="ods"){}     else {         $status = 'sorry file extension not allowed';         return redirect::back()->with(session()->flash('error_flash_message', $status));     }      // $file = time().'.'.$request->file->getclientoriginalextension();     $path = $file->move(public_path('uploads'), $file);      $data = excel::load($path, function($reader) {         })->get();       if(!empty($data) && $data->count()){         foreach ($data $key => $value) {             $insert[] = [                         'cat_id' => $value->cat_id, 'car_name' => $value->car_name                         ,'starting_price' => $value->starting_price                         ,'image' => $value->image , 'car_name_ar' => $value->car_name_ar                         ,'year_start' => $value->year_start , 'year_end' => $value->year_end                     ];         }         if(!empty($insert)){             db::table('cars')->insert($insert);          }     }     return redirect()->back()->with('success', true); } 

and that's form

<form method="post" action="uploadedcars" enctype="multipart/form-data" >          select excel-sheet upload:     <input type="file" name="file" id="file">   <br>     <button class="btn btn-primary" type="submit" name="submit"> upload sheet </button> </form> 

can me ? when dd() returned data uploading gives me nothing , , excel sheet not empty ?

replace line

$path = $file->move(public_path('uploads'), $file); 

with

$destinationpath = 'uploads'; $file->move($destinationpath,$file->getclientoriginalname()); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -