mafortis
mafortis

Reputation: 7138

laravel file does not exist or is not readable

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

one

Issue

When I upload my file it uploads, my database also gets 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?

Upvotes: 5

Views: 38833

Answers (4)

pankaj
pankaj

Reputation: 1914

I was facing the same issue. then I changed my PHP.ini file setting where I changed 2 settings.

upload_max_filesize and post_max_size

make a change here. set the upload_max_filesize : 512M and post_max_size:256M.

re-run the PHP artisan server. 100% of your issue will be fixed. No need to change your laravel code.

Upvotes: 0

tom biz
tom biz

Reputation: 59

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!

Upvotes: 5

Suraj Inamdar
Suraj Inamdar

Reputation: 221

check your php.ini...make sure that your upload_max_filesize is as big as your post_max_size.

https://github.com/laravel/framework/issues/31249

Upvotes: 9

elad gasner
elad gasner

Reputation: 745

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

Upvotes: 19

Related Questions