How to upload video with Laravel

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: How to Upload Videos with Laravel - A Comprehensive Guide Introduction The Laravel framework provides an elegant API for web development, making it easier to build powerful applications. One of its essential features is handling file uploads, including images and videos. In this blog post, we'll discuss how to easily implement video upload functionality within your Laravel application. Prerequisites Before proceeding, ensure you have the following set up: 1. An installed and configured Laravel project. 2. A working database with a suitable table for storing uploaded videos (if required). 3. Web server support for video streaming, like Apache or Nginx. You can use PHP's built-in functionality if you wish to stream the video directly from your web server. 4. A basic understanding of Laravel routing and controllers. Steps to Upload a Video with Laravel 1. Controller: Begin by creating a new controller, `VideoUploadController`, to handle the upload process. 2. Routes: Define a route for handling video uploads. Add this route in your `routes/web.php` file: ```php Route::post('/upload-video', 'VideoUploadController@uploadVideo'); ``` 3. View: Create a simple view to display the form for users to upload videos. Include a file input field, a submit button and any other relevant form fields. 4. Controller Method: Define a new method in your controller to handle the video upload process. This method should have validation rules and error handling in case of invalid data. Here's an example: ```php public function uploadVideo(Request $request) { // Validation rules for video file size, extension, etc. if($validator = Validator::make($request->all(), [ 'video_file' => 'required|mimes:mp4,webm,ogg|max:10240', ])->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } // Process video upload and store in desired location. $videoFile = $request->file('video_file'); if ($videoFile) { $fileName = time() . '.' . $videoFile->getClientOriginalExtension(); $videoFile->move(storage_path('app/public'), $fileName); } else { return redirect()->back()->withErrors('No video file selected')->withInput(); } // Store video details in the database (if required). Video::create([ 'title' => $request->input('title'), 'description' => $request->input('description'), 'video_url' => '/storage/' . $fileName, ]); } ``` 5. View: Include a view with the necessary HTML form elements and submit button to allow users to upload videos. The form should have an action pointing to your defined route in Step 2: ```html
{{ csrf_field() }}
``` 6. Database migration: If you want to store additional details about the uploaded videos, such as title, description, or tags, create a new table in your database with appropriate columns. Migrate this schema using Laravel's built-in commands. Handling Video Streaming If you wish to stream the video directly from your web server rather than storing it in the file system (or any other storage), make sure your web server supports video streaming, and update the code accordingly: 1. Controller: Store the URL for the video's location instead of saving it in storage_path(). The controller method should return the URL to the client so that the browser can stream the video directly from the server. 2. View (optional): Include a form field with an `<iframe>` or `<video>` tag as a placeholder for the uploaded video. This will enable users to preview the videos in your application, even before they are saved to storage. Conclusion By following these steps, you now have the knowledge to implement an effective video upload feature within your Laravel application. Remember to test, secure, and optimize your solution as needed, ensuring a smooth user experience while maintaining strong data security practices.