CodeIgniter Forums
Files in "writable" / Preview via "http" not working, ideas? - 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: Files in "writable" / Preview via "http" not working, ideas? (/showthread.php?tid=81842)



Files in "writable" / Preview via "http" not working, ideas? - Renkman - 05-09-2022

Hey folks,
I try to code something like a file browser (Win: Explorer/Mac: Finder), very small but working with all folders and files.
My understanding is to create a subfolder in "writable", and it works, I can do and view all files and folders, upload works too, but... my "Preview function" has some problems. 
I use a javascript to preview .pdf files and this script needs an url.
Maybe I missed something, but building urls for me is only working if files are in the "public" directory, files in the directory "writable" cannot accessed by url, e.g. https://mydomain/writable/server/images/photo.jpg
It seems I have to code a separate controller to make these files visible, but I'm not sure. A want to avoid to move the server folder to public (or should I???). In public folder it wouldn't be a problem.

Has anybody a solution or idea?


RE: Files in "writable" / Preview via "http" not working, ideas? - iRedds - 05-09-2022

If you store files in a "writable" directory, then you need a controller that will handle access to those files.


RE: Files in "writable" / Preview via "http" not working, ideas? - MGatner - 05-15-2022

iRedds nailed it. If you want to read more these are using called “media servers”. You need a routed controller that can “serve” the files since the writable folder is not web-accessible.

An alternative (but make sure you handle security implications) is to create a symlink in public/ to the files.

You may be interested in this similar project: https://github.com/tattersoftware/codeigniter4-files