Skip to content
Advertisement

Intervention / Image Upload Error {{ Image source not readable }}

I am trying to add a profile image upload in Laravel 5.1. I used the Intervention/Image Package but when I try to upload the image I get this error:

NotReadableException in AbstractDecoder.php line 302: Image source not readable

This is my PhotoController:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use Image;
use Input;
use AppHttpRequests;
use AppHttpControllersController;

class PhotoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function index() {}

    /**
     * Show the form for creating a new resource.
     *
     * @return IlluminateHttpResponse
     */
    public function create() {}

    /**
     * Store a newly created resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpResponse
     */
    public function store(Request $request)
    {
        $img = Image::make($request->file('photo')); 
        $img->save('image.png');  
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function show($id) {}

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function edit($id) {}

    /**
     * Update the specified resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function update(Request $request, $id) {}

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function destroy($id) {}
}

This is my html form:

<header>
    <div class="student_profile_sub_header w100">
        <div class="container ccenter">
            <div class="student_profile_name">
                <h4>{{$student->name}} {{$student->surname}}</h4>
            </div>
            <div class="student_profile_image">
                <img src="{{asset('assets/profile_image.png')}}">
            </div>

            <form method="POST" action="../student/profile/imageupload">
                {!! csrf_field() !!}
                <input type="file" name="photo">
                <input type="submit" value="Upload Image" name="submit">
                @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </form>
        </div>
    </div>
</header>

Advertisement

Answer

Add the following parameter in your form tag:

enctype="multipart/form-data"

And change for this in make:

$img = Image::make($request->file('photo')->getRealPath());
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement