CodeIgniter Forums
How to retrieve images from /writable/uploads to be displayed? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to retrieve images from /writable/uploads to be displayed? (/showthread.php?tid=81287)



How to retrieve images from /writable/uploads to be displayed? - castle - 02-13-2022

Hi, 

I know that /writable folder cannot access directly on URL since it's outside the public folder. But here is my setup:

- I have a CRUD for manufacturers. For the create.php page, it's allowed the manufacturer logo to be uploaded. The logo is stored at /writable/uploads.
- At edit.php page, the uploaded logo is previewed, and the manufacturer can update the logo if needed. 

So, how can I display the image? Should I save the image at /public/uploads instead?
Thanks;


RE: How to retrieve images from /writable/uploads to be displayed? - iRedds - 02-13-2022

This is not a framework level question.
If the image should be available to everyone, then it makes no sense to store it outside the public folder.
If access is limited, read the file and output.


RE: How to retrieve images from /writable/uploads to be displayed? - includebeer - 02-13-2022

You can use the Publisher library: https://codeigniter.com/user_guide/libraries/publisher.html
I never used it but it looks like it would address your problem:
Quote:How do I manage uploads and other “dynamic” files that need to be web accessible?



RE: How to retrieve images from /writable/uploads to be displayed? - castle - 02-13-2022

(02-13-2022, 01:25 PM)iRedds Wrote: This is not a framework level question.
If the image should be available to everyone, then it makes no sense to store it outside the public folder.
If access is limited, read the file and output.

I think it is framework related. The setup I mentioned is pretty common, and it's one of the reasons why people use frameworks. The reason I don't want to use /public is because my Frontend user doesn't need to know about my Backend vendor's logo. There are some dynamic images that should be available only for the Backend. 

I've asked to check if CI4 has a way of doing that, since as I said, it's a pretty common setup.

(02-13-2022, 03:27 PM)includebeer Wrote: You can use the Publisher library: https://codeigniter.com/user_guide/libraries/publisher.html
I never used it but it looks like it would address your problem:
Quote:How do I manage uploads and other “dynamic” files that need to be web accessible?

Thank you for the heads-up.


RE: How to retrieve images from /writable/uploads to be displayed? - InsiteFX - 02-14-2022

public
-- assets
---- images
---- js
---- uploads
---- etc


Then you can access them like this.

PHP Code:
href="<?= base_url('assets/uploads/name.png'); ?>" 



RE: How to retrieve images from /writable/uploads to be displayed? - castle - 02-14-2022

(02-14-2022, 02:24 AM)InsiteFX Wrote: public
-- assets
---- images
---- js
---- uploads
---- etc


Then you can access them like this.

PHP Code:
href="<?= base_url('assets/uploads/name.png'); ?>" 

Ok. Thank you.

I got it worked in a way. My solution was getting the image and converting to data - base64 - using img_data(). Then, preview it. This way, I don't need to move the image around or to put it into /public folder. I can keep it at /writable. I'm only using this to show up the image when the admin wants to edit an entry.

I'm not sure if it's the "correct" way or if it has any flaw, but it's working.


RE: How to retrieve images from /writable/uploads to be displayed? - Paradinight - 02-14-2022

Use xsendfile (Apache) or X-Accel-Redirect

https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/