![]() |
storing images outside of public_html - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: storing images outside of public_html (/showthread.php?tid=16091) Pages:
1
2
|
storing images outside of public_html - El Forum - 02-24-2009 [eluser]samseko[/eluser] My system folder is below the public viewable folder. I have a sub-folder under system called uploads, which is where the uploaded images go. I have their respective direct file path + name in a database, and tagged to a specific member. Is it possible to then reference this path and any image based on direct path in a view file, as opposed to the conventional way of storing them all in the public_folder and using standard html calls? I need to keep all images out of public viewable area and only allow member to see his / her own images. storing images outside of public_html - El Forum - 02-24-2009 [eluser]TheFuzzy0ne[/eluser] You'll probably just need a controller that will work as the front end. The user can request the image via the controller, and the controller can validate them to ensure that they are their images. If it's not, return nothing, or some kind of default warning image. storing images outside of public_html - El Forum - 02-24-2009 [eluser]samseko[/eluser] I'm still confused on how i would load the images though -- simple if they are within the public viewable area, but unsure how that would be achieved under the public folder and with a direct path. Code: <img src="/home/profile/system/uploads/img.gif"> storing images outside of public_html - El Forum - 02-24-2009 [eluser]Jelmer[/eluser] Use PHP's readfile() function: http://www.php.net/manual/en/function.readfile.php And don't forget to output the correct MIME type before you use the readfile function. For example like this: Code: // for security reasons, don't allow "../" in the request URI storing images outside of public_html - El Forum - 02-25-2009 [eluser]samseko[/eluser] I cannot get that code to work -- for some reason it is asking me to download the file as a random 'part' when i try to view the members page with that code. storing images outside of public_html - El Forum - 02-25-2009 [eluser]TheFuzzy0ne[/eluser] Please show us your controller. storing images outside of public_html - El Forum - 02-25-2009 [eluser]samseko[/eluser] Basic call to the view file from the controller. The view file has: Code: // for security reasons, don't allow "../" in the request URI storing images outside of public_html - El Forum - 02-25-2009 [eluser]TheFuzzy0ne[/eluser] It should be a controller, not a view. ./system/application/libraries/MY_Controller.php Code: <?php You could then use something like this from within your view. Code: <img src="/somecontroller/user_images/someimage.jpg" /> I haven't done it all for you... This is just an example to hopefully demonstrate one possible method to achieve the results you're after. There are probably many other ways to achieve the same thing. Without knowing your application structure, it's hard to comment on which method will be best for you. Hope this helps. storing images outside of public_html - El Forum - 02-25-2009 [eluser]Jelmer[/eluser] There's more wrong with the code. The following does nothing usefull: Code: $server_request = str_replace('../../system/uploads/', '', $_SERVER['REQUEST_URI']); Code: str_replace('../', '', $_SERVER['REQUEST_URI']); Code: $file = '../../system/uploads/feb09-001.jpg'; storing images outside of public_html - El Forum - 02-25-2009 [eluser]samseko[/eluser] TheFuzzy0ne, Jelmer: it works!! I used the combination of both your previous posts. The image file was static as i was testing to see if it would work before i polled the database. Thanks heaps guys!! |