skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    I solved it :

    $image_name=$post->id.'_'.$image_counter.'.jpg';
    $image->move('/images/posts/', $image_name);  // just remove : public_path().
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search