Welcome Guest, Not a member yet? Register   Sign In
$this->load->file(), but don't treat it as PHP...
#1

[eluser]sheldonnbbaker[/eluser]
Hi everyone,

New to CI but I've been making a simple asset controller to serve up css, javascript, and images to give me a little more control of what I serve out in terms of requests.

Anyways, this is what I have for outputting PNGs:

Code:
$this->output->set_header("Content-type: text/png");
        
$this->load->file('system/application/views/assets/img/' . $this->uri->rsegment(3) . '.png');

($this->uri->rsegment(3) is the name of the file).

Problem is this: I'm getting PHP errors, like this one:

Quote:[23-Jan-2009 14:46:10] PHP Parse error: syntax error, unexpected T_STRING in ...../system/application/views/assets/img/body-background.png on line 4

Is there a way to just have it return the file's contents, and not read it like a PHP file? Something equivalent to fread() or file_get_contents()?

Thanks Smile
#2

[eluser]Tom Schlick[/eluser]
i highly recommend not putting your assets in the CI app folder. it give who ever visits your site a sitemap of your entire app structure and can pose some security concerns.
#3

[eluser]Colin Williams[/eluser]
Quote:$this->load->file('filepath/filename', true/false)

This is a generic file loading function. Supply the filepath and name in the first parameter and it will open and read the file. By default the data is sent to your browser, just like a View file, but if you set the second parameter to true (boolean) it will instead return the data as a string.

But anyway, trs21219 is right. Doesn't seem like the best setup.
#4

[eluser]darkhouse[/eluser]
Agreed. My setup is generally like this:

css
flash
images
js
system
applications
etc...

That way your source paths are simple, like
Code:
<img src="images/some_pic.png" />
#5

[eluser]sheldonnbbaker[/eluser]
Hmm - okay - I'll look at putting them back at the web root.

Not quite sure how it'd be a security risk though - could you please expand on how it would be? I should also mention that I have my /system/ folder outside of my web root.

Thanks for the help

EDIT: Still getting the same error when I pass TRUE as the second argument. However, I extended the loader class and added my own asset() method, which fopen()s and freads() the file, and I don't get the error that I do when I use load->file().




Theme © iAndrew 2016 - Forum software by © MyBB