I am trying to send zip file in laravel but i receive this error:
When I upload my file it uploads
, also my database get updates
so basically no problem with physical file nor database data the only issue is that i receive this error somehow!
Here is my controller code
public function sendCompanyData(Request $request)
{
$this->validate($request, array(
'coDoc' => 'required|mimetypes:application/zip|max:10000',
));
$company = CompanyData::where('user_id', Auth::user()->id)->first();
//file
if ($request->hasFile('coDoc')) {
$coDoc = $request->file('coDoc');
$filename = $company->user->username . '-Company-Prove-Documents-' . str_random(10) . '-' . time() . '.' . $coDoc->getClientOriginalExtension();
$location = public_path('files/idus/');
$request->file('coDoc')->move($location, $filename);
$oldFilename = $company->files;
$company->files = $filename;
if(!empty($company->files)){
Storage::delete($oldFilename);
}
$company->files = $filename;
}
$company->save();
//send confirmation mail
$userMail = $company->user->email;
$data = array(
'id' => $company->id,
'user' => $company->user->username,
'files' => url('files/idus', $company->files),
'submit_time' => $company->created_at->format('d M, Y | H:m:s A'),
);
Mail::to($userMail)->send(new MailToAdmin($data));
return redirect()->back();
}
Any idea?
You need to check if you have an error like: "The file "***.jpg" exceeds your upload_max_filesize ini directive (limit is 2048 KiB)."
like $coDoc->getErrorMessage()
I fix it !
do not use "move" function for save your file
I use Storage::disk('public')->putFileAs and work
I think can't move tmp file in laravel version 6!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With