Welcome Guest, Not a member yet? Register   Sign In
How to retrieve images from /writable/uploads to be displayed?
#1

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;
Reply
#2

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.
Reply
#3

You can use the Publisher library: https://codeigniter.com/user_guide/libra...isher.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?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#4

(This post was last modified: 02-13-2022, 05:32 PM by castle.)

(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/libra...isher.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.
Reply
#5

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


Then you can access them like this.

PHP Code:
href="<?= base_url('assets/uploads/name.png'); ?>" 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(This post was last modified: 02-14-2022, 05:04 AM by castle.)

(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.
Reply
#7

Use xsendfile (Apache) or X-Accel-Redirect

https://www.nginx.com/resources/wiki/sta...xsendfile/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB