You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
60 lines
2.0 KiB
<?php
|
|
|
|
if (!function_exists('uploadFile')) {
|
|
function uploadFile($file, $folder = null)
|
|
{
|
|
$type_file = explode("/", $file->getMimeType())[0];
|
|
if (!empty($folder)) {
|
|
$file_path = "uploads/" . $folder ?? "file";
|
|
} else {
|
|
$file_path = "uploads/" . $type_file ?? "file";
|
|
}
|
|
$fileName = "bsr_" . $type_file . time(). uniqid() . '.' . $file->extension();
|
|
$file->move(public_path($file_path), $fileName);
|
|
return [
|
|
'file_name' => $fileName,
|
|
'type_file' => $type_file,
|
|
'file_path' => $file_path
|
|
];
|
|
}
|
|
}
|
|
if (!function_exists('isJson')) {
|
|
function isJson($string)
|
|
{
|
|
json_decode($string);
|
|
return json_last_error() === JSON_ERROR_NONE;
|
|
}
|
|
}
|
|
if (!function_exists('upload_avatar')) {
|
|
function upload_avatar($avatar, $folder_name = null)
|
|
{
|
|
$fileName = null;
|
|
if (!empty($avatar) && $avatar !== "null") {
|
|
$fileName = time() . '.' . $avatar->extension();
|
|
if (!empty($folder_name)) {
|
|
$avatar->move(public_path('uploads/image/' . $folder_name), $fileName);
|
|
} else {
|
|
$avatar->move(public_path('uploads/image/'), $fileName);
|
|
}
|
|
}
|
|
return $fileName;
|
|
}
|
|
}
|
|
if (!function_exists('convert_excel_to_array')) {
|
|
function convert_excel_to_array($folder)
|
|
{
|
|
$path_file = public_path() . "/" . $folder . '/example.xlsx';
|
|
// return file_get_contents($path_file);
|
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
|
// Tell the reader to only read the data. Ignore formatting etc.
|
|
$reader->setReadDataOnly(true);
|
|
// Read the spreadsheet file.
|
|
$spreadsheet = $reader->load($path_file);
|
|
$sheet = $spreadsheet->getSheet($spreadsheet->getFirstSheetIndex());
|
|
$data = $sheet->toArray();
|
|
|
|
// output the data to the console, so you can see what there is.
|
|
unset($data[0]);
|
|
return $data;
|
|
}
|
|
}
|
|
|