fbc's avatar
Level 2

File upload not being stored

I am trying to upload a file and save it.

There is no error, however no file is saved.

This is the save function:

        // Handle the user upload of a file
        if($request->hasFile('audit')){
            $audit = $request->file('audit');
            $filename = time() . '.' . $audit->getClientOriginalExtension();
            Storage::put( public_path('/uploads/audits/' . $filename ), $request->file('audit') );

            $audit = new Audit;
            $audit->property_id = $request->propertyid;
            $audit->title = $request->title;
            $audit->filename = $filename;
            $audit->type = $request->audit_type;
            $audit->save();
        }

I took my code for saving an avatar and tried to alter it to work with regular files instead of just images.

Here is the original code for that function I started off with:

    public function update_avatar(Request $request){

        // Handle the user upload of avatar
        if($request->hasFile('avatar')){
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename ) );

            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();
        }

        return view('profile', array('user' => Auth::user()) );

    }
0 likes
3 replies
fbc's avatar
fbc
OP
Best Answer
Level 2

I couldn't get that function to work for the life of me.

ended up going with this:

        if($request->hasFile('audit')){
            $audit = new Audit;

            $file = $request->file('audit');
            $fileName = $file->getClientOriginalName();
            $request->file('audit')->move(public_path('/uploads/audits/'),$fileName);

            $audit->property_id = $request->propertyid;
            $audit->title = $request->title;
            $audit->filename = $fileName;
            $audit->type = $request->audit_type;
            $audit->save();
        }
rkrite's avatar

Could it be that your web server doesn't allow uploads of a version size? Try increasing the max upload setting on your web server.

Please or to participate in this conversation.