vish_youtube vish_youtube - 1 month ago 17
MySQL Question

How to upload video with Laravel

I'm trying to upload a video while using Laravel. Though uploading images work fine for me when I change my controller line

echo '$file' . $file->getClientOriginalName() . '"/>';


to:

echo '<file src="uploads/' . $file->getClientOriginalName() . '"/>';


I only see
uploaded
written on a new page, but no video.

Controller:

<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request;


class UploadController extends Controller
{

public function upload(Request $request)
{

if(Request::hasFile('file')){

echo 'Uploaded';
$file = Request::file('file');
$file->move('uploads', $file->getClientOriginalName());
echo '$file' . $file->getClientOriginalName() . '"/>';
}

}
}


Routes:

Route::get('/', function () {
return view('welcome');
});

Route::post('upload', 'UploadController@upload');


View:

<html>
<head>
<title>Laravel</title>

<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>

</head>
<body>
<div class="container">
<div class="content">

<h1>File Upload</h1>
<form action="{{ URL::to('upload') }}" method="post" enctype="multipart/form-data">
<label>Select image to upload:</label>
<input type="file" name="file" id="file">
<input type="submit" value="Upload" name="submit">
<input type="hidden" value="{{ csrf_token() }}" name="_token">
</form>

</div>
</div>
</body>
</html>

Answer

You can try like this:

Controller :

use Illuminate\Support\Facades\Request;


class UploadController extends Controller
{

    public function upload(Request $request)
    {

        if(Request::hasFile('file')){

            $file = Request::file('file');
            $filename = $file->getClientOriginalName();
            $path = public_path().'/uploads/';
            return $file->move($path, $filename);
        }

    }
}

php.ini files contains some limits that might affect this. Try changing these to high enough values:

upload_max_filesize = 10M
post_max_size = 10M
memory_limit = 32M