vendredi 16 octobre 2015

Trying to display image encoded in base64

I'm trying to display my image (encoded in base64) on my browser.

This is what I had tried:

        {{$projects}}
        <hr>
        @foreach ($projects as $project)
            @if ($project['name'] != null)
                <p>Project {{ $project['name'] }}</p>
                <img src="data:image/{{$project['image_type']}};base64,{{$project['image']}}" alt="Project picture" >
            @endif
        @endforeach

Which looks like this on the browser link: http://ift.tt/1jt2kxZ

Unfortunately that didn't work out.

Before displaying an image. I had uploaded an image to my database with the following code:

public function store(Request $request)
{   
    if($request['file'] != null) {
        $file = $request['file'];
        $fileName = $file->getClientOriginalName();
        $imageType = pathinfo($fileName, PATHINFO_EXTENSION);

    } else {
        $fileName = null;
        $imageType = null;
    }
    Project::create([
        'name' => $request['name'],
        'content' => $request['content'],
        'image' => base64_encode($fileName),
        'image_type' => $imageType,
    ]);

    return redirect('/projects');
}

Can someone maybe tell me what I'm doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Rg3dnN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire