How we rename in this code in laravel controller?
I want to rename our file need to add prefix and suffix with timestamp i.e. FAS_12062024.png.
Now we get something like this “bRpBIKjkY4VCiEbH7jVVS6JjEv7ffs9f7CzuOhXC” file name in laravel 10.
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");
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;
}
how do we rename upload file in this above code. except that “csv”
New contributor
neo4ru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.