如何使用Laravel上传视频 [英] How to upload video with Laravel

查看:234
本文介绍了如何使用Laravel上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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() . '"/>';

收件人:

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

我只看到uploaded写在新页面上,但没有视频.

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

控制器:

<?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() . '"/>';
        }

    }
}

路线:

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

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

查看:

<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>

推荐答案

您可以尝试以下操作:

控制器:

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文件包含一些可能会影响此的限制.尝试将这些值更改为足够高的值:

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

这篇关于如何使用Laravel上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆