Picking up the contents of an image I made from my folder

0

Good I have a form that uploads images, these images are played in the directory: uploads/{idcampaign}/images/

In my PHP controller how do I access this image and get its contents?

    public function get($id) {

      /** @var  UploadedFile $file */

      $image = $this->repository->byId($id)->first();
      $url = "/storage/app/" + $image->path;
      if($image) {
          return response()->file($url , ['Content-Type' => 'image.png | 
      image.jpeg']);
    }
      throw new NotFoundHttpException('image-not-found');
    }

I tried this and it did not. I just need to get into the image and grab its contents to be able to return to the view.

    
asked by anonymous 11.01.2018 / 19:37

1 answer

1

When questions of this type arise, do not hesitate to refer to documentation . Basically you can use the file function, accessed from the response object.

Applying, stay:

return response()->file($url);

But it will probably be necessary to send some headers in response, such as the mime of the file. Example:

 return response()->file($url, ['Content-Type' => 'image/png']);
    
11.01.2018 / 22:58