I´m trying upload one file to storage/app
with laravel for this, i´m checking that my folder exist:
if(isset($request->file_job)){
$pathFolder = storage_path('app/contratos/'.$tarea->contratoTrey->serie->SERIE.'-'.$tarea->contratoTrey->N_CONTRATO.'/tareas/T-'.$tarea->ntarea);
if(!\File::exists($pathFolder)) {
\File::makeDirectory($pathFolder, 0755, true, true);
}
$filePath = 'app/contratos/'.$tarea->contratoTrey->serie->SERIE.'-'.$tarea->contratoTrey->N_CONTRATO.'/tareas/T-'.$tarea->ntarea;
\Storage::disk('local')->put($filePath, $request->file_job);
}
if not exist i´m building my structure folder and put my file in this folder.
My problem it´s in my DB i´m insert my file name with getClientOriginalName()
but in this route
'app/contratos/'.$tarea->contratoTrey->serie->SERIE
my app was builded a file, not directory and in this directory my file with his original name...
i don´t know that i´m doing wrong.. i trayed creating a new variable with this name and save... same error or problem...
Thanks for readme and help me. Sorry for my bad english
CodePudding user response:
The issue might be that you are using put instead of putFileAs. You can find the documentation in https://laravel.com/docs/9.x/filesystem#specifying-a-file-name so, instead of:
\Storage::disk('local')->put($filePath, $request->file_job);
You should:
\Storage::disk('local')->putFileAs($filePath, $request->file_job, ($request->file_job)->getClientOriginalName());