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>
If you want to upload big files you should use streams. Here's the code to do it: $disk = Storage::disk('s3'); $disk->put($targetFile, fopen($sourceFile, 'r+')); PHP will only require a few MB of RAM even if you upload a file of several GB.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With