How to load files when stored OUTSIDE public folder |
[eluser]Christophe28[/eluser]
Hello, I'm a new user of codeigniter. I wonder how to load photos when they are stored OUTSIDE the public folder. I used to simply get the filename out the database and load it in the view, something like: Code: <img src="http://mydomain.com/uploads/<?php echo $filename; ?>" /> So how to tell codeigniter to search for the files outside the public folder and then pass it to the view? Thx for any help or suggestions! Christophe
[eluser]benurv[/eluser]
just make a variable containing the folder eg: $files = /hosting/yourdomain/etc/... and use it in your view, i always store files outside of my ci root for security reasons when those files need to be accessed publically, i use a function to pick up the file by id or so and serve it to the browser
[eluser]Eric Barnes[/eluser]
It is more secure to have your php files outside your web root. However javascript, css, and images all have to be accessible via the web. So you can't move them to a place that isn't accessible.
[eluser]WanWizard[/eluser]
You could write some code that uses get_file_contents(), something like: Code: $details = getimagesize($path . '/' . $image);
[eluser]Christophe28[/eluser]
Hi, Waw, thank you for all the support. Christophe
[eluser]Jelmer[/eluser]
I use readfile() for this goal. I'm not entirely sure but I think it's more efficient. readfile() writes the file's contents directly to the output buffer while file_get_contents() first reads it into PHP and then has to write it through PHP. Which I'd guess is less efficient. The same code using readfile(): Code: $details = getimagesize($path . '/' . $image);
[eluser]WanWizard[/eluser]
You're absolutely right. I just wrote down the first thing that came to mind, this is a better (and especially with larger images) and a faster solution. |
Welcome Guest, Not a member yet? Register Sign In |