2017-07-19 4 views
0

-Controllercsv Hochladen nicht Laravel

public function uploadFile() 
{ 
     if(isset($_POST["uploadFile"])){ 
     $filePath = realpath($_FILES["file"]["tmp_name"]); //GETTING THE FULL PATH OF THE FILE WHICH WANTS TO BE SAVED INTO THE DB 
     $arr = []; 
      if (($handle = fopen($filePath, 'r')) !== FALSE){ 
       $i = 0; 
       while (($lineArray = fgetcsv($handle, 4000)) !== FALSE){ 
        for ($j=0; $j<count($lineArray); $j++){ 
         $arr[$i][$j] = $lineArray[$j]; 
        } $i++; 
       } fclose($handle); 
      } 
     $csv = array_slice($arr,1); 
     foreach($csv as $line){ 
      mysqli_query($mysqli, "INSERT INTO dialog(`eType`,`eVal`,`intent`,`reply`) VALUES('$line[0]','$line[1]','$line[2]','$line[3]')"); //FOR EACH LINE SAVE INTO THE DB 
     } 
     } 
} 

Strecke

Route::get('uploadFile', 'Chatbot\[email protected]'); 

Ansicht

<form method="post" action="{{action('AltHr\Chatbot\[email protected]')}}" enctype="multipart/form-data"> 
     <input type="file" name="file"> <br> 
     <button type="submit" name="uploadFile" class="btn alt-btn-black btn-xs alt-btn">UPLOAD FILE</button> 
</form> 

Also mit db, Seine meine erste da y Lernen Laravel, kann mir jemand sagen, warum ich diesen errror MethodNotAllowedHttpException habe in RouteCollection.php

Ich versuche, eine CSV Datei in der Form in der Datenbank zu laden. Was mache ich hier falsch?

+3

für die Post einzufügen müssen Sie 'Strecke :: Post' Routing-Methode, anstelle von "Route :: Get" –

+0

Guys, jetzt habe ich diesen Fehler "TokenMismatchException in VerifyCsrfToken.php" – Rajveer

+0

löschen Sie bitte Cache, 'php Artisan Cache: clear' –

Antwort

3

Ihre Route ist falsch. Upload ist POST Anfrage:

Route::post('uploadFile', 'Chatbot\[email protected]'); 
-1

Die eigentliche Frage ist: Warum sind Sie nicht Eloquent oder zumindest die Querybuilder mit der Deutschen Bahn Anfrage