Laravel 5.2 PHP Build a social network – Image Upload



Build a complete Social Network Web Application with PHP Laravel. In this video you will see how file upload in Laravel works and how we can use it to store an user image.
More on storage in Laravel:

Complete source code:

Complete Laravel-course on Udemy: (Coupon: YOUTUBE1)

In this course we’ll build a neat little…

, , , , , , ,

35 thoughts on “Laravel 5.2 PHP Build a social network – Image Upload

  1. Hi Max, the image upload seems to be working fine for me, and i see the file in my file system, when i use the "<img src="{{ route('account.image', ['name' => $user->name . '-' . $user->id . '.jpg']) }}" alt="" class="img-responsive">" code to show the image, the app gets the full path in the view source, but it doesnt render to the screen, do you know what could cause this?

  2. Hey, I hope someone could give me some help.

    I have been working on this for a couple of days and I can't figure it out. When I try to upload an image nothing happens (I also don't get an error). I am pretty sure it is because somehow it is not getting the image when I hit the button.

    postSaveAccount method:

    namespace AppHttpControllers;
    use AppUser;
    use IlluminateHttpRequest;
    use IlluminateHttpResponse;
    use IlluminateSupportFacadesAuth;
    use IlluminateSupportFacadesFile;
    use IlluminateSupportFacadesStorage;
    $file = $request->file('image');
    $filename = $user->first_name. '-' . $user->id . '.jpg';
    if($request->hasFile('image')){
    Storage::disk('local')->put($filename, File::get($file));
    }
    return redirect()->route('account');

    account.blade.php:
    @section('content')
    <section class="row new-post">
    <div class="col-md-6 col-md-offset-3">
    <header><h3>Your Account</h3></header>
    <form action="{{ route('account.save') }}" method="POST" enctype="multipart/form-data">
    <div class="form-group">
    <label for="first_name">First Name</label>
    <input type="text" name="first_name" class="form-control" value="{{ $user->first_name }}" id="first_name">
    </div>
    <div class="form-group">
    <label for="image">Image (only .jpg)</label>
    <input type="file" name="image" class="form-control" id="image">
    </div>
    <button type="submit" class="btn btn-primary">Save Account</button>
    <input type="hidden" value="{{ Session::token() }}" name="_token">
    </form>
    </div>
    </section>
    @if (Storage::disk('local')->has($user->first_name . '-' . $user->id . '.jpg'))
    <section class="row new-post">
    <div class="col-md-6 col-md-offset-3">
    <img src="{{ route('account.image', ['filename' => $user->first_name . '-' . $user->id . '.jpg']) }}" alt="" class="img-responsive">
    </div>
    </section>
    @endif
    @endsection

    I hope someone can help, I've been stuck for weeks. I've even tried to copy and paste the github code exactly, but continue to get errors. Thanks.

    EDIT: I am not sure if this helps, but I am currently using the 5.4 version

  3. In new laravel version there is no more need in Storage facade. You can just use this construction:
    $file = $request->file('image');
    $filename = $request->first_name . '-' . $user->id . '.jpg';

    if($file)
    {
    $file->storeAs('images', $filename);
    }

  4. Don't you think that using name of the user is quite Dangerous, because he can change his name only, then we will not be able to retrieve his/her image because the name has been changed

  5. Hey, I've been following your tutorial for about a week now.. all the codes are correct(i guess) as i reviewed it for several times already and its seems correct. updating the name and uploading the image works fine however Im having an error everytime i press the "save account" button – its keeps on showing me this error – "InvalidArgumentException in UrlGenerator.php line 314:
    Route [acount] not defined. " – but image and name are updating after refreshing the page. any solution for this? please reply.. Thanks btw for the tutorial! youre great!

  6. does this method work for mobile photo uploads as well??
    Like Lets say that the user uploads a mobile photo that is 5 mb in size and turned 90 degress. would this method compress the image and turn it 90 degrees upright or would one have create a process to do that???

  7. I keep getting the Error:
    MethodNotAllowedHttpException in RouteCollection.php line 218:
    I almost changed everything refering to you github clone, Do you know what I might be missing?

  8. I have Put all these on the top but still the image is not displaying
    use AppUser;
    use IlluminateHttpRequest;
    use IlluminateHttpResponse;
    use IlluminateSupportFacadesAuth;
    use IlluminateSupportFacadesFile;
    use IlluminateSupportFacadesStorage;

  9. Hello Max! Thank you for your tutorials, they are very handy! The image upload to me works just the way you showed it in your tutorial, yet there's one thing: If I right click that image (the image loads perfectly on the page) to open in new tab, I get some very weird stuff, just about what Paul explained below. Is that supposed to be like that?

  10. i am having error

    FatalErrorException in UserController.php line 74:
    Class 'AppHttpControllersFile' not found

    72 if ($file)
    73 {
    74 Storage::disk('local')->put($filename, File::get($file));
    }

    and code is same as video…!!!!

    as video github code is little bit diffrent so i didn't copied it

Leave a Reply

Your email address will not be published. Required fields are marked *