Loading...

Laravel Saving file from http post request

  
					
  
//check if request has file called file
if($request->hasFile('file')){
    //get file name with extension
   $filenameWithExt = $request->file('file')->getClientOriginalName();
   //get just file name
   $filename = $request->file($filenameWithExt, PATHINFO_FILENAME) ;
   //get just ext
   $extension = $request->file('file')->getClientOriginalExtension();
   //file name to store
   $fileNameToStore = $filename.'_'.time().'.'.$extension;
   $fileNameToStore = $request->image.'_'.$request->serial.'.'.$extension;
    $path = $request->file('file')->storeAs('public', $fileNameToStore);
    return new StationResources(["message" => "Image saved succesfully"]);
}else{
    return new StationResources(["Message" => "Image not found"]);
}  

Leave a Reply

Your email address will not be published. Required fields are marked *