在Laravel中使用上传信息确认表单后显示弹出窗口

时间:2016-08-31 20:17:56

标签: laravel file-upload popup

我在laravel 5.2中有一个网页,其中包含一个表单,您必须输入一个视频文件才能上传到我的服务器。

这是表格:

@extends('layouts.app')

@section('content')
<link href='assets/vendor/parsleyjs/src/parsley.css' rel='stylesheet' />

@if (Auth::guest())
<script type="text/javascript">
    window.location = "/";//here double curly bracket
</script>
@else
    @if ((Auth::user()->tipo != "profesor") && (Auth::user()->tipo != "alumno"))

    <script type="text/javascript">
        window.location = "/";//here double curly bracket
    </script>
    @endif
@endif
<H3 style="margin-top: 0">Subir Video</H3>

{!! Form::open(['id' => 'newVideo', 'route' =>'upload.store', 'method'=>'POST', 'files'=> true, 'data-parsley-validate'=>'' ]) !!}

<div class = "form-group" style ="display: none;">
    {!! Form::label('usuario_id', 'usuario_id:') !!}
    {!! Form::text('usuario_id', Auth::user()->id) !!}
</div>

<div class = "form-group" style ="display: none;">
    {!! Form::label('state', 'State:') !!}
    @if (Auth::user()->tipo == "alumno")
        {!! Form::text('state', 3) !!}
    @else
        {!! Form::text('state', 1) !!}
    @endif
</div>

    {!! Form::label('name', 'Nombre * :') !!}
    {!! Form::text('name', null, ['class'=> 'form-control', 'required'=> '']) !!}

    {!! Form::label('description', 'Descripción * :') !!}
    {!! Form::textarea('description', null, ['class'=> 'form-control', 'required'=> '']) !!}

    {!! Form::label('language', 'Idioma * :') !!}
    {!! Form::select('language', Config::get('enums.languages'), ['required'=> '', 'data-parsley-mincheck'=> 1]) !!}

<div class = "form-group">
    {!! Form::label('imageRef', 'Imagen Referencial de Video * :') !!}
    {!! Form::file('imageRef', ['required'=> '']) !!}
</div>

<div class = "form-group">
    {!! Form::label('url', 'Video * :') !!}
    {!! Form::file('url', ['required'=> '']) !!}
</div>

<div class = "form-group">
    {!! Form::label('subtitle', 'Subtitulos:') !!}
    {!! Form::file('subtitle') !!}
</div>

<div class = "form-group">
    {!! Form::label('trailer', 'Trailer * :') !!}
    {!! Form::file('trailer', ['required'=> '']) !!}
</div>
    {!! Form::submit('Registrar',['class' =>'btn btn-primary', 'value' =>'validate']) !!}
    {!! Form::close() !!}
@endsection

路线:

Route::resource('upload','MovieController');

Controller函数(MovieController):

public function store(Request $request)
    {
        /*$validator = Validator::make($request->all(), [$this->validationRules]);

        if ($validator->fails()){
            return redirect()->back()->withErrors($validator->errors());
        }*/

        $movie = Movie::create([
            'usuario_id' => $request['usuario_id'],
            'asignatura_id' => $request['asignatura_id'],
            'name' => $request['name'],
            'visit' => $request['visit'],
            'language' => $request['language'],
            'creation_date' => $request['creation_date'],
            'description' => $request['description'],
            'imageRef' => $request['imageRef'],
            'url' => $request['url'],
            'state' => $request['state'],
            'production_year' => $request['production_year'],
            'category' => $request['category'],
            'category2' => $request['category2'],
            'shooting_format' => $request['shooting_format'],
            'direction' => $request['direction'],
            'direction_assistant' => $request['direction_assistant'],
            'casting' => $request['casting'],
            'continuista' => $request['continuista'],
            'script' => $request['script'],
            'production' => $request['production'],
            'production_assistant' => $request['production_assistant'],
            'photografic_direction' => $request['photografic_direction'],
            'camara' => $request['camara'],
            'camara_assistant' => $request['camara_assistant'],
            'art_direction' => $request['art_direction'],
            'mounting' => $request['mounting'],
            'image_postproduction' => $request['image_postproduction'],
            'sound_postproduction' => $request['sound_postproduction'],
            'catering' => $request['catering'],
            'music' => $request['music'],
            'actors' => $request['actors'],
        ]);
        $movieId = $movie->id;

        if($request['subtitle'] != null){
            $sub = Subtitle::create([
                'video_id' => $movieId,
                'url' => $request['subtitle'],
                ]);
            }
        if($request['trailer'] != null){
            $trailer = Trailer::create([
                'video_id' => $movieId,
                'url' => $request['trailer'],
                ]);
            if($request['trailer_subtitle'] != null){
                $trailerId = $trailer->id;

                $subTrailer = Subtitle::create([
                    'trailer_id' => $trailerId,
                    'url' => $request['trailer_subtitle'],
                    ]);
            }
        }        
        return "OK";
    }

模特:

class Movie extends Model
{
    protected $table = "movies";

    protected $fillable = ['usuario_id','asignatura_id','name','language','creation_date','description','imageRef','url','state','production_year','category','category2','shooting_format','direction','direction_assistant','casting','continuista','script','production','production_assistant','photografic_direction','camara','camara_assistant','art_direction','sonorous_register','mounting','image_postproduction','sound_postproduction','catering','music','actors'];

    public function setImageRefAttribute($imageRef){

        $this->attributes['imageRef'] = Carbon::now()->second.$imageRef->getClientOriginalName();
        $name = Carbon::now()->second.$imageRef->getClientOriginalName(); 
        \Storage::disk('local')->put($name, \File::get($imageRef));
    }
    public function setUrlAttribute($url){

        $this->attributes['url'] = 'old/'.Carbon::now()->second.$url->getClientOriginalName();
        $name = Carbon::now()->second.$url->getClientOriginalName();
        \Storage::disk('local')->put($name, \File::get($url));

        $file = pathinfo($name,PATHINFO_FILENAME); 
        $extension = pathinfo($name,PATHINFO_EXTENSION);

        $ffmpeg = \FFMpeg\FFMpeg::create([
            'ffmpeg.binaries'  => '/Applications/MAMP/htdocs/FFmpeg/ffmpeg',
            'ffprobe.binaries' => '/Applications/MAMP/htdocs/FFmpeg/ffprobe',
            'timeout'          => 0, // The timeout for the underlying process
            'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use

        ]);
        $video = $ffmpeg->open($url);
        //$format = new CustomVideo();
        $format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');
        $format->on('progress', function ($video, $format, $percentage) {
            echo "$percentage % transcoded";
        });
        $format
        -> setKiloBitrate(1000)
        -> setAudioChannels(2)
        -> setAudioKiloBitrate(256);

        $video
        ->save($format, 'files/convert/videos/'.$file.'.mp4');
        $this->attributes['url'] = $file.'.mp4';

        $ffmpeg_path = '/Applications/MAMP/htdocs/FFmpeg/ffmpeg'; //Path to your FFMPEG
        $video_path = 'files/convert/videos/'.$file.'.mp4'; // Path to your Video

        $command = $ffmpeg_path . ' -i "' . $video_path . '" -vstats 2>&1';

        $output = shell_exec($command);
        $regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
        $hours = 0;
        if (preg_match($regex_duration, $output, $regs)) {
            $hours = $regs [1] ? $regs [1] : null;
            $mins = $regs [2] ? $regs [2] : null;
            $secs = $regs [3] ? $regs [3] : null;
            $video_Length = $hours . ":" . $mins . ":" . $secs;
            $this->attributes['duration'] = $video_Length;
        }

        /*->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
    ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
    ->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');*/

//audio
/*        $ffmpeg = FFMpeg\FFMpeg::create();
        $audio = $ffmpeg->open('track.mp3');

        $format = new FFMpeg\Format\Audio\Flac();
        $format->on('progress', function ($audio, $format, $percentage) {
            echo "$percentage % transcoded";
        });

        $format
        -> setAudioChannels(2)
        -> setAudioKiloBitrate(256);

        $audio->save($format, 'track.flac');*/

    }

    public static function Movies(){
        return DB::table('movies')
        ->join('subjects','subjects.id','=','movies.asignatura_id')
        ->select('movies.*')
        ->get();
    }
}

我需要在提交表单时显示弹出窗口,其中包含类似于xibo popup的视频上传信息,但更简单。

我需要这样的东西:

enter image description here

我找不到解决方案。

0 个答案:

没有答案