I'm writing a script to deal with forms. For now I don't have a database setup, so I'm testing using Session::flash.
Everything is working great, but I can't get the name of the file that gets saved, and I will need it to have it saved on database and then create a download link with it for another user.
I tried several ways and can't seem to make it work.
public function AltComiss(Request $request)
{
$name1 = array( ($request->input('test')),
($request->input('test1')),
($request->input('test2')),
($request->input('test3')),
($request->input('test4')) );
for ($i=0; $i <= 10; $i++) {
if (($request->input('comiss'.$i)) !== null) {
array_push($name1, ($request->input('comiss'.$i)));
array_push($name1, ($request->input('desconto'.$i)));
}
}
array_push($name1, ($request->input('test7')));
Session::flash('allInput',$name1);
if ($request->hasFile('file2')) {
$file = $request->file('file2');
$destinationPath = 'altComiss';
$filename = 'AlteraComissao-' . time() . '.' . $file->getClientOriginalExtension();
$file->storeAs($destinationPath, $filename);
array_push($name1, $filename);
}
return redirect('alteracaocomissao');
}
Everything is working great, all inputs get saved on Session(which later will be inserted into DB), and the file does get uploaded where I want it. But I can't save the filename, which I will need to retrieve it.
Thanks in advance!
You're pushing $filename
to an array $name1
. It looks like you're using $name1
on another page since you're flashing that data to the session.
The problem is you're flashing the data to the session before you push $filename
.
Flash $name1
to the session after you push $filename
to $name1
, or store $filename
somewhere else. You don't seem to be using that variable anywhere else.
$file = $request->file('file2')->getClientOriginalName();
You should try this approach to get the name. Run in a similar problem like yours recently.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.