main
Ilham Wara Nugroho 2026-03-26 11:31:09 +07:00
parent 63cbe19971
commit f9ce9672bc
1 changed files with 20 additions and 42 deletions

View File

@ -152,50 +152,28 @@ class DatasetTambahanController extends Controller
// $sheet = $spreadsheet->getActiveSheet(); // $sheet = $spreadsheet->getActiveSheet();
// $rows = $sheet->toArray(); // $rows = $sheet->toArray();
// $header = $rows[4]; // Baris pertama sebagai header // $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);
$destinationPath = public_path('uploads/dataset');
$current = Carbon::now()->format('Y/m/d');
// for ($i = 5; $i < count($rows); $i++) { $path = $destinationPath . '/' . $current;
// $row = $rows[$i]; $fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
// // Skip baris kosong $fileExtension = $file->getClientOriginalExtension();
// if (collect($row)->filter()->isEmpty()) continue; $fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx')){
// $assoc = []; return redirect()->back()->with([
// foreach ($header as $j => $columnName) { 'message' => 'Maaf File Harus Berupa pdf,docx,xls,xlsx!',
// if($columnName != null){ 'type' => "error"
// $assoc[strtolower(str_replace(' ','_',$columnName))] = $row[$j] ?? null; ]);
// }
// }
// $data[] = $assoc;
// }
} }
$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);
} }