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

(This post was last modified: 07-21-2023, 09:47 PM by iRedds.)

1. You don't need to call the send() method. At least if you don't know how it works and what consequences it will cause.
2. The solution to your case will be in version 4.4.
3. To display the file in the browser, the header "Content-Disposition: inline" is needed. But in the current implementation, this header will be overwritten.

The easiest TEMPORARY solution for you would be...

1. Take the DownloadResponse class from the repository from the 4.4 branch (https://github.com/codeigniter4/CodeIgni...sponse.php)
2. Save the file in the application directory app/DownloadResponse.php
3. In the file, change the namespace from "CodeIgniter\HTTP" to "App".
4. Next, in the controller method, call the following code.
PHP Code:
(new \App\DownloadResponse('1.webp'true))->setFilePath(ROOTPATH 'private/1.webp')->inline()->send();
exit(
0); 

I haven't tested it, but in theory it should work.
When you upgrade to version 4.4, use the ready-made solution described in the documentation. And without calling send() and exit().
Reply


Messages In This Thread
RE: Return Image to the Browser from Private Folder - by iRedds - 07-21-2023, 09:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB