![Cara Upload dan Membaca File CSV Laravel](https://ullilfahri.b-cdn.net/storage/app/photos/ullil.png)
Cara Upload dan Membaca File CSV Laravel
Pada Form
<form method="POST" enctype="multipart/form-data" action="{{ url('/uploadakm') }}">
<input type="file" class="form-control" name="csv"><br>
<input type="hidden" name="prodi" value="{{ $prodi }}">
<input type="hidden" name="akt" value="{{ $akt }}">
<input type="hidden" name="smt" value="{{ $sms }}">
<input type="submit" value="Upload" class="btn btn-info">
@csrf
</form>
Cara Upload
public function upload(Request $request)
{
$request->file('csv')->storeAs('data', "data.csv");
$file = fopen('storage/app/data/data.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
$data[] = $line;
}
fclose($file);
$prodi = $request->prodi;
$akt = $request->akt;
$sms = $request->smt;
//dd($kelas);
// dd($data);
return view('aktifitasmhs.data', [
'data' => $data,
'prodi' => $prodi,
'akt' => $akt,
'sms' => $sms
]);
}
Cara Membaca
public function prosesneo($prodi, $akt, $smt)
{
error_reporting(0);
$file = fopen('storage/app/data/data.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
//$line is an array of the csv elements
//print_r($line);
$data[] = $line;
}
fclose($file);
// dd($data);
}
Lanjut Part : 1
Muhammad Ullil Fahri
WA : 089696380422
Tautan WA : https://wa.me/message/SG4YA2XQP5FPE1