Welcome Guest, Not a member yet? Register   Sign In
Return Image to the Browser from Private Folder
#1
Photo 

Hi,

CodeIgniter 4 has the DownloadResponse class that presents a dialog box in the browser to download the file.

However, I have images in a folder outside the public directory.
And I would like to let the browser directly display (not download) the image after a successful authorization.
Since the images are in a private folder, an image URL can't be shared.

I'm able to successfully return the download response from the controller that prompts a dialog box in the browser to save the image.
However, I don't know if there is a way to have a CodeIgniter controller return an image so that the browser could straight display it?
If I cancel the dialog box, the page remains empty

All the examples I searched on the internet are about using readfile() but I'm not sure how do I use it either with a HTTP response or download response.

URL: https://www.localwebsite.test/attachment/1.webp
attachment is the name of the controller

So how do I return image to the browser from private folder for display purpose?

PHP Code:
return $this->response->download(ROOTPATH 'private/1.webp'nulltrue)->send(); 

[Image: Screenshot-2023-07-21-at-11-19-26-PM.png]
Reply


Messages In This Thread
Return Image to the Browser from Private Folder - by amit - 07-21-2023, 11:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB