skip to Main Content

i have a project that it has some posts on it
i have made admin panel to create new posts
since i uploaded my project on cpanel host i can create a post but image wont shown in my post but before that on my localhost i can craete a post and store image in my path
i checked my public path in my host and saw that there isn,t any new image related to my post that i have created with my admin panel on my host just my image name has saved in my database

this is my blog blade file

<section class="w-80 mx-auto my-5">
    <div class="container">
        <div class="row">
            @foreach($posts as $post)
                <div class="col-md-4 translate-box relative mb-4">
                    <div class="blog-box-height">
                        <a href="{{route('blog.single',['title'=>$post->title])}}"> <img src="{{asset('image/'.$post->header_image)}}" alt="{{$post->title}}" class="img-fluid"></a>
                        <div class="py-3 px-4">
                            <a class="text-xmedium fw-bold text-decoration-none text-black" href="{{route('blog.single',['title'=>$post->title])}}">
                                {{str_replace('_',' ',$post->title)}}
                            </a>
                            <p class="text-muted-1 mt-2 text-small">
                               {!! strip_tags(mb_substr($post->content,0,270,'utf-8')) !!} ...
                            </p>
                            <div class="box-time absolute">
                                <p class="text-muted-1"><i class="far fa-clock"></i> {{$post->time}} دقیقه</p>
                            </div>
                        </div>
                    </div>
                </div>
            @endforeach
        </div>
    </div>
</section>

this is my postcontroller codes

public function storeImage(Request $request)
{
    $image_name = null;
    if ($request->file('image')) {
        $image = $request->file('image')->getClientOriginalName();
        $image_name = time() . $image;
        $folder = public_path('/image');
        $path = $folder . '/' . $image_name;

        if (is_dir($folder)) {
            $img = Image::make($request->file('image'))->resize(500, 438);
            $img->save($path);
        } else {
            File::makeDirectory($folder, 0755, true);
            $img = Image::make($request->file('image'))->resize(500, 438);
            $img->save($path);
        }
    }

    return $image_name;
}

this code works great in my localhost server but when i uploaded it on host i think image intervation wont work

2

Answers


  1. You have to set the symlink to connect the stroge folder with the public folder.
    Try running php artisan storage:link on the webserver.

    Also in some hostings this command is banned. In that case you have to create the symlink manually using forexample midnight commander.

    Login or Signup to reply.
  2. Try with 777 permission for make directory.

    File::makeDirectory($folder, 0777, true);

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