Using php to serve javascript and css files
Posted: Tue Oct 11, 2011 6:04 pm
I'm setting up a multitenant system for clients using my software, in which there is one instance stored on my server and each client has his own folder and database with his personal settings. The application is stored in a folder inaccessible through the web. Right now, all client-side included files, like CSS and JavaScript, are stored in each client's individual folder. What I would like to do is store application-side CSS and JavaScript files, like the core AJAX handler or the CSS file for the admin panel, in the application folder, and serve the files through a specific call in the URL query string.
So, something like http://www.mysite.com?view=include&file=admin.css would render the contents of the admin.css file in the non-web-accessible application folder.
I got this to work with javascript, but I can't get it to work with css...I think I'm missing some sort of content type declaration.
Here's the code for my view class:
I created a JavaScript file that just has alert('test');, included it with this method, and it worked:
But, the browsers don't like it when I include a CSS file using a <link> tag in the header. It's grabbing the text from the file, but the browser doesn't seem to be recognizing it at CSS.
Any ideas?
Thanks.
So, something like http://www.mysite.com?view=include&file=admin.css would render the contents of the admin.css file in the non-web-accessible application folder.
I got this to work with javascript, but I can't get it to work with css...I think I'm missing some sort of content type declaration.
Here's the code for my view class:
Code: Select all
<?php
namespace application\views;
class Includer extends \application\auth\Normal {
public function load() {
$file = getQueryVar('file');
if(file_exists(CN_APPLICATION_PATH.'includes/'.$file)) {
echo file_get_contents(CN_APPLICATION_PATH.'includes/'.$file);
}
}
}
?>Code: Select all
<script type="text/javascript" src="<?=SITE_URL?>?view=include&file=test.js"></script>Any ideas?
Thanks.