4 months ago

Odd image upload issue

Posted 4 months ago by MattB

I have an odd issue with displaying the result of a file upload form. Below is the code for the upload:

public function store(Request $request){
        if($file = $request->file('image')){
          $name = $file->getClientOriginalName();
          $path = 'images';
          if($file->move($path, $name)){
            $post = new Gallery();
            $path = '../public/images';
            $post->image = $path . '/' . $name;
            $post->name = $request->name;
            $post->species_id = $request->species_id;
            $post->tag = $request->tag;
            $post->patreon = $request->patreon;
            return redirect()->route('');

It uploads all the images ok, but when I display them with the following code, some will show on the page as expected, but some show a 404 error. They are showing in the folder specified ok and in the db, it's showing the correct file path (correct path in the Chrome dev console too). I have no idea what's going on here.


  <div class="container galleryContainer">
    <div class="display-4">Gallery</div><br>
    <ul class="galleryList">
      @foreach($mainGallery as $gallery)
      <li><p>{{$gallery->name}}</p><a href="{{$gallery->image}}" target="_blank"><img src="{{$gallery->image}}" alt="" class="img-thumbnail" width="200" height="400"></a></li>

Please sign in or create an account to participate in this conversation.