-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?
für die Post einzufügen müssen Sie 'Strecke :: Post' Routing-Methode, anstelle von "Route :: Get" –
Guys, jetzt habe ich diesen Fehler "TokenMismatchException in VerifyCsrfToken.php" – Rajveer
löschen Sie bitte Cache, 'php Artisan Cache: clear' –