Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel file does not exist or is not readable

Tags:

php

laravel

I am trying to send zip file in laravel but i receive this error:

one

Issue

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!

Code

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?

like image 389
mafortis Avatar asked Jan 26 '23 16:01

mafortis


2 Answers

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()

like image 197
elad gasner Avatar answered Jan 28 '23 04:01

elad gasner


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!

like image 44
tom biz Avatar answered Jan 28 '23 06:01

tom biz