lundi 20 février 2017

Uploading a video with URL Laravel 5.1

i have a form where i add an image and a video but what i wanna try is uploading it to the DB with a youtube URL, and then watch it on the web app. I am also worried if i send this it uploads me twice the image ?

This is my store function (saving it through file) video and image.

$data = $request->all();
        $image = $request->file('image');
        $video = $request->file('video');

        if($image)
        {
            $data['image'] = $image->getClientOriginalName();
        }

        $company_outstand = new CompanyOutstand($request->all());
        $company_outstand->fill($request->all());
        $company_outstand->image = $data['image'];
        $company_outstand->save();

        if($company_outstand->image){
            $path = public_path() . '/image/company_outstand/' . $company_outstand->id;
            if( ! File::exists($path)) {
                File::makeDirectory($path, 0775, true, true);
            }
            $imageName = $company_outstand->image;
            $request->file('image')->move($path, $imageName);

        }

        if($video)
        {
            $data['video'] = $video->getClientOriginalName();
        }

        $company_outstand = new CompanyOutstand($request->all());
        $company_outstand->fill($request->all());
        $company_outstand->video = $data['video'];
        $company_outstand->save();

        if($company_outstand->video){
            $path = public_path() . '/video/company_outstand/' . $company_outstand->id;
            if( ! File::exists($path)) {
                File::makeDirectory($path, 0775, true, true);
            }
            $videoName = $company_outstand->video;
            $request->file('video')->move($path, $videoName);

        }

My form view for edit and create:

<div class="form-group">
    {!! Form::label('text', 'Texto') !!}
    {!! Form::text('text', null, ['class' => 'form-control', 'placeholder' => 'Texto', 'required']) !!}
</div>
<div class="form-group">
    {!! Form::label('order', 'Orden') !!}
    {!! Form::text('order', null, ['class' => 'form-control', 'placeholder' => 'Orden', 'required']) !!}
</div>
<div class="form-group">
    {!! Form::label('Imagen ') !!}
</div>
<div class="form-group">
    @if( ! isset($company_outstand->image))
        <div class="col-sm-6">
            {!! Form::file('image', null, array('class' => 'image')) !!}
        </div>
    @else
        <div class="col-sm-6">
            <img class="thumbnail" src="/image/company_outstand//" width="200" height="100">
            {!! Form::text('image', $company_outstand->image, array('class' => 'image hidden')) !!}
            {!! Form::file('image', null, array('class' => 'image', 'form-control')) !!}
        </div>
    @endif
</div>
<div class="form-group">
    @if( ! isset($company_outstand->video))
        <div class="col-sm-6">
            {!! Form::file('video', null, array('class' => 'video')) !!}
        </div>
    @else
        <div class="col-sm-6">
            <img class="thumbnail" src="/video/company_outstand//" width="200" height="100">
            {!! Form::text('video', $company_outstand->video, array('class' => 'video hidden')) !!}
            {!! Form::file('video', null, array('class' => 'video', 'form-control')) !!}
        </div>
    @endif
</div>
<div class="form-group">
    {!! Form::submit('Guardar', ['class' => 'btn btn-primary']) !!}
</div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire