Anonymous
Переименовать файл в контроллере Laravel
Сообщение
Anonymous » 25 июн 2024, 07:25
Как мы переименовываем этот код в контроллере laravel?
Я хочу переименовать наш файл, нужно добавить префикс и суффикс с отметкой времени, т.е. FAS_12062024.png.
Теперь мы получаем что-то вроде этого файла «bRpBIKjkY4VCiEbH7jVVS6JjEv7ffs9f7CzuOhXC» имя в laravel 10.
Код: Выделить всё
elseif ($row->type == 'file') {
if ($row->subtype == "fineuploader") {
$fileSize = number_format($row->max_file_size_mb / 1073742848, 2);
$fileLimit = $row->max_file_size_mb / 1024;
if ($fileSize < $fileLimit) {
$values = [];
$value = explode(',', $request->input($row->name));
foreach ($value as $file) {
$values[] = $file;
}
$row->value = $values;
} else {
return response()->json(['is_success' => false, 'message' => __("Please upload maximum $row->max_file_size_mb MB file size.")], 200);
}
} else {
if ($row->file_extention == 'pdf') {
$allowedFileExtension = ['pdf', 'pdfa', 'fdf', 'xdp', 'xfa', 'pdx', 'pdp', 'pdfxml', 'pdxox'];
} else if ($row->file_extention == 'image') {
$allowedFileExtension = ['jpeg', 'jpg', 'png'];
} else if ($row->file_extention == 'excel') {
$allowedFileExtension = ['xlsx', 'csv', 'xlsm', 'xltx', 'xlsb', 'xltm', 'xlw'];
}
$requiredextention = implode(',', $allowedFileExtension);
$fileSize = number_format($row->max_file_size_mb / 1073742848, 2);
$fileLimit = $row->max_file_size_mb / 1024;
if ($fileSize < $fileLimit) {
if ($row->multiple) {
if ($request->hasFile($row->name)) {
$values = [];
$files =$request->file($row->name);
foreach ($files as $file) {
$extension = $file->getClientOriginalExtension();
$check = in_array($extension, $allowedFileExtension);
if ($check) {
if ($extension == 'csv') {
$name = \Str::random(40) . '.' . $extension;
$file->move(storage_path() . '/app/form-values/' . $form->id, $name);
$values[] = 'form-values/' . $form->id . '/' . $name;
} else {
$path = Storage::path("form-values/$form->id");
$fileName = $file->store('form-values/' . $form->id);
if (!file_exists($path)) {
mkdir($path, 0777, true);
chmod($path, 0777);
}
if (!file_exists(Storage::path($fileName))) {
mkdir(Storage::path($fileName), 0777, true);
chmod(Storage::path($fileName), 0777);
}
$values[] = $fileName;
}
как переименовать файл загрузки в приведенном выше коде. кроме этого "csv"
Подробнее здесь:
https://stackoverflow.com/questions/786 ... controller
1719289520
Anonymous
Как мы переименовываем этот код в контроллере laravel? Я хочу переименовать наш файл, нужно добавить префикс и суффикс с отметкой времени, т.е. FAS_12062024.png. Теперь мы получаем что-то вроде этого файла «bRpBIKjkY4VCiEbH7jVVS6JjEv7ffs9f7CzuOhXC» имя в laravel 10. [code]elseif ($row->type == 'file') { if ($row->subtype == "fineuploader") { $fileSize = number_format($row->max_file_size_mb / 1073742848, 2); $fileLimit = $row->max_file_size_mb / 1024; if ($fileSize < $fileLimit) { $values = []; $value = explode(',', $request->input($row->name)); foreach ($value as $file) { $values[] = $file; } $row->value = $values; } else { return response()->json(['is_success' => false, 'message' => __("Please upload maximum $row->max_file_size_mb MB file size.")], 200); } } else { if ($row->file_extention == 'pdf') { $allowedFileExtension = ['pdf', 'pdfa', 'fdf', 'xdp', 'xfa', 'pdx', 'pdp', 'pdfxml', 'pdxox']; } else if ($row->file_extention == 'image') { $allowedFileExtension = ['jpeg', 'jpg', 'png']; } else if ($row->file_extention == 'excel') { $allowedFileExtension = ['xlsx', 'csv', 'xlsm', 'xltx', 'xlsb', 'xltm', 'xlw']; } $requiredextention = implode(',', $allowedFileExtension); $fileSize = number_format($row->max_file_size_mb / 1073742848, 2); $fileLimit = $row->max_file_size_mb / 1024; if ($fileSize < $fileLimit) { if ($row->multiple) { if ($request->hasFile($row->name)) { $values = []; $files =$request->file($row->name); foreach ($files as $file) { $extension = $file->getClientOriginalExtension(); $check = in_array($extension, $allowedFileExtension); if ($check) { if ($extension == 'csv') { $name = \Str::random(40) . '.' . $extension; $file->move(storage_path() . '/app/form-values/' . $form->id, $name); $values[] = 'form-values/' . $form->id . '/' . $name; } else { $path = Storage::path("form-values/$form->id"); $fileName = $file->store('form-values/' . $form->id); if (!file_exists($path)) { mkdir($path, 0777, true); chmod($path, 0777); } if (!file_exists(Storage::path($fileName))) { mkdir(Storage::path($fileName), 0777, true); chmod(Storage::path($fileName), 0777); } $values[] = $fileName; } [/code] как переименовать файл загрузки в приведенном выше коде. кроме этого "csv" Подробнее здесь: [url]https://stackoverflow.com/questions/78663860/rename-file-in-laravel-controller[/url]