skip to Main Content

I am trying to upload images on a shared hosting but am unable to upload. On my machine it works well but when I host i cant figure how to change the paths.All the other pages are working fine except uploading images.

on my controller
foreach ($images as $image){
         $move=$image->move(public_path().'/images2/',time().'_'.$image->getClientOriginalName()); 
         if($move){
         $imagedata=Images::create([
        'title'=>time().'_'.$image->getClientOriginalName(),
        'filename'=>time().'_'.$image->getClientOriginalName()
        ]);

Displaying the previous images is okay with this code on the view side

 @foreach($product_images as $image)
    <div class="carousel-item {{ $loop->first ? 'active' : '' }}">
     <div> <img class="d-block w-100 newim" src="/images2/{{$image->filename}}"/></div>
    </div>
@endforeach

2

Answers


  1. Chosen as BEST ANSWER

    I added this to index php though not sure whether it is secure but it works

    $app->bind('path.public', function() {
      return realpath(__DIR__.'/../public_html/');
    });
    

  2. i think your problem is here with the wrong "," :

    $move=$image->move(public_path().'/images2/',time().'_'.$image->getClientOriginalName());
    

    change it to:

    $move=$image->move(public_path().'/images2/'.time().'_'.$image->getClientOriginalName());
    

    and make sure your folders are same name as you wrote in your code because host is sensitive to uppercase or lowercase

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