From f9ce9672bce1dfb6315864eee8e0440a7de56b19 Mon Sep 17 00:00:00 2001 From: Ilham Wara Nugroho Date: Thu, 26 Mar 2026 11:31:09 +0700 Subject: [PATCH] update --- .../Opendata/DatasetTambahanController.php | 62 ++++++------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/app/Http/Controllers/Opendata/DatasetTambahanController.php b/app/Http/Controllers/Opendata/DatasetTambahanController.php index 2312755..a78f6dc 100644 --- a/app/Http/Controllers/Opendata/DatasetTambahanController.php +++ b/app/Http/Controllers/Opendata/DatasetTambahanController.php @@ -152,50 +152,28 @@ class DatasetTambahanController extends Controller // $sheet = $spreadsheet->getActiveSheet(); // $rows = $sheet->toArray(); // $header = $rows[4]; // Baris pertama sebagai header - if (@$request->hasFile('file')) { - $file = $request->file('file'); - dd($file); - $destinationPath = public_path('uploads/dataset'); - $current = Carbon::now()->format('Y/m/d'); - $path = $destinationPath . '/' . $current; - $fileName = $file->getClientOriginalName(); - $fileMime = $file->getClientMimeType(); - $fileExtension = $file->getClientOriginalExtension(); - $fileSize = $file->getSize(); - if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx')){ - return redirect()->back()->with([ - 'message' => 'Maaf File Harus Berupa pdf,docx,xls,xlsx!', - 'type' => "error" - ]); - } - $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; - - if (!File::exists($path)) { - File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); - } - - $filePath = 'dataset/' . $current . '/' . $newFilename; - $uploaded = $file->move($path, $newFilename); - - - // for ($i = 5; $i < count($rows); $i++) { - // $row = $rows[$i]; - - // // Skip baris kosong - // if (collect($row)->filter()->isEmpty()) continue; - - // $assoc = []; - // foreach ($header as $j => $columnName) { - // if($columnName != null){ - // $assoc[strtolower(str_replace(' ','_',$columnName))] = $row[$j] ?? null; - // } - // } - - // $data[] = $assoc; - // } - + $destinationPath = public_path('uploads/dataset'); + $current = Carbon::now()->format('Y/m/d'); + $path = $destinationPath . '/' . $current; + $fileName = $file->getClientOriginalName(); + $fileMime = $file->getClientMimeType(); + $fileExtension = $file->getClientOriginalExtension(); + $fileSize = $file->getSize(); + if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx')){ + return redirect()->back()->with([ + 'message' => 'Maaf File Harus Berupa pdf,docx,xls,xlsx!', + 'type' => "error" + ]); } + $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; + + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $filePath = 'dataset/' . $current . '/' . $newFilename; + $uploaded = $file->move($path, $newFilename); }