There are few step
Step 1
Create FileUpload Model
1 |
php artisan make:model FileUpload |
Step 2
Create upload function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
namespace App; use File; use Storage; class FileUpload { public static function photo($request,$fileName,$default="") { $name = ""; $photo=$request->photo; if($request->hasFile($fileName)) { $extension=$photo->getClientOriginalExtension(); $name=rand(11111,99999).".".date('Y-m-d').".".time().".".$extension; Storage::disk('photo')->put($name,File::get($photo)); $name = $name; }else{ $name=$default; } return $name; } } |
Step 3
Create function in controller and add these lines
1 2 3 4 5 6 7 8 9 10 11 12 13 |
use App\Http\Requests; use App\FileUpload; use File; use Storage; class WebsitePages extends Controller { public function UploadFile(Request $request) { $photoname=FileUpload::photo($request,'photo'); // 'photo' is form input file name echo $photoname; // uploaded file name } } |
Leave a reply