Support the ongoing development of Laravel.io →
posted 6 years ago
Input Forms
Last updated 7 months ago.
0
Solution

Fixed! The problem was that on the online server, the application folder is placed OUTSIDE the public_html folder. Therefore the public_path() was pointing at the "wrong" folder.

# root
## laravel
## public_html
### images
#### users

Therefore the application was uploading the images into

# root
## laravel
### public
#### images

I managed to resolve this with a quick fix in the controller.

if ($request->file('profile_pic')->isValid()) {
    $path = base_path();
    $path = str_replace("laravel", "public_html", $path); // <= This one !
    $destinationPath = $path . '/images/users'; // upload path
    $extension = $request->file('profile_pic')->getClientOriginalExtension(); // getting image extension
    $fileName = uniqid() . '.' . $extension; // renameing image
    $request->file('profile_pic')->move($destinationPath, $fileName); // uploading file to given path
    $user->profilepic = $fileName;
}
Last updated 6 years ago.
0

Sign in to participate in this thread!

Cloudways

Your banner here too?

3svb 3svb Joined 16 Feb 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.