Level 122
use the docs as an example
https://laravel.com/docs/5.8/filesystem#file-uploads
use PutFileAs method described there.
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()) );
}
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();
}
Please or to participate in this conversation.