Reputation: 99
I have Laravel website saving images viya controller, I uploaded the project on server host, in public_html folder I put public folder files. other folders and files put on folder outside public_html
/home/domain_user
public_html
|__ images
project_folder
|__app
|__bootstrap
|__ public
|__images
when I save Images it saved in project_folder->public->images and when i used assets to view images it use images in :public_html->images
save image code :
$image_name=$post->id.'_'.$image_counter.'.jpg';
$image->move(public_path().'/images/posts/', $image_name);
view image code :
$image='images/posts/'.$post->id.'_1.jpg';
<img class="img-fluid" src="{{ asset($image) }}" alt="Third slide">
How can I save and vuew image to and from same path?
Upvotes: 0
Views: 51
Reputation: 99
I solved it :
$image_name=$post->id.'_'.$image_counter.'.jpg';
$image->move('/images/posts/', $image_name); // just remove : public_path().
Upvotes: 0
Reputation: 13
You have to change the public folder direction. (default is on laravel/public)
add this code to bootstrap/app.php:
$app->usePublicPath(realpath(__DIR__.'/../../public_html'));
If not works, use second way:
$app->bind('path.public', function() {
return realpath(__DIR__.'/../../public_html');
});
Anyway, it is better to use Storage so that you don't have these problems.
Upvotes: 0