The Little Guy Posted December 24, 2007 Share Posted December 24, 2007 what is the best way to out put a css file from another file, so it is as if you are viewing the actual css file? i used readfile() and include but neither of these work, it just outputs the file like plain HTML non-styled text. Quote Link to comment https://forums.phpfreaks.com/topic/83017-file-output/ Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 you mean you want to use the style attributes from another CSS file? try this: <style type="text/css"> <?php include('file.css'); ?> </style> Quote Link to comment https://forums.phpfreaks.com/topic/83017-file-output/#findComment-422258 Share on other sites More sharing options...
The Little Guy Posted December 24, 2007 Author Share Posted December 24, 2007 No, that isn't what I want, that is what I have... it doesn't work. My site routes sub domains through a file using htaccess, and that file creates the output for the page, so it displays like a normal website. The problem is, that CSS files, and JavaScript files display as normal HTML output, and that the line breaks are not put in, and it isn't formated like a normal css document. Here is my sites output: http://test.hostbox.us/style.css Here is a normal sites output: http://tzfiles.com/style.css see how the formatting is different? I would like the first one to display like the second one. Quote Link to comment https://forums.phpfreaks.com/topic/83017-file-output/#findComment-422263 Share on other sites More sharing options...
wildteen88 Posted December 24, 2007 Share Posted December 24, 2007 You are sending the wrong content type header for the first link (http://test.hostbox.us/style.css). Your browser is receiving the text/html content type and thus the new lines are not displaying. You will need to send the text/css content type header in order for the browser to display the newlines. How is style.css being routed. Could you explain your setup. Quote Link to comment https://forums.phpfreaks.com/topic/83017-file-output/#findComment-422319 Share on other sites More sharing options...
The Little Guy Posted December 24, 2007 Author Share Posted December 24, 2007 .htaccess file: Options +FollowSymLinks RewriteEngine On # Fix missing trailing slashes. RewriteCond %{HTTP_HOST} !^(www\.)?hostbox\.us$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.hostbox\.us$ [NC] RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] # Rewrite sub domains. RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{HTTP_HOST} !^(www\.)?hostbox\.us$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.hostbox\.us$ [NC] RewriteRule ^(.*)$ viewFile.php?user=%2&file=$1 [QSA,L] #RewriteRule ^(.*)$ subdomains/%2/$1 [QSA,L] The line to output the CSS/JS is on about line 15 The file that actually displays the output: <?php $file = '/home/ryannaddy/hostbox.us'; if(isset($_GET['file'])){ if(empty($_GET['file'])&&file_exists($file.'/subdomains/'.$_GET['user'].'/index.php')){$f = 'index.php';$s = 'index.php';} elseif(empty($_GET['file'])&&file_exists($file.'/subdomains/'.$_GET['user'].'/index.htm')){$f = 'index.htm';$s = 'index.htm';} elseif(empty($_GET['file'])&&file_exists($file.'/subdomains/'.$_GET['user'].'/index.html')){$f = 'index.html';$s = 'index.html';} else{$s = $_GET['file'];$f = $_GET['file'];} }else{ $f = $_GET['file']; $s = $_GET['file']; } $file .= '/subdomains/'.$_GET['user'].'/'.$f; if(file_exists($file)){ if(preg_match("~^(.*).(css|js)$~",$file)){ readfile($file); }else{ echo'<div style="margin:auto;width:728px;padding-bottom:5px;"> <script type="text/javascript"><!-- google_ad_client = "pub-6797482378713025"; //hostbox.us Header google_ad_slot = "5160918041"; google_ad_width = 728; google_ad_height = 90; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div>'; include $file; } }else{ header("HTTP/1.0 404 Not Found"); include('/home/ryannaddy/hostbox.us/err/404.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83017-file-output/#findComment-422448 Share on other sites More sharing options...
The Little Guy Posted December 24, 2007 Author Share Posted December 24, 2007 OK, thank you for the header thing. I added header("Content-type: text/css");[\b] before the output, and it works perfect! Quote Link to comment https://forums.phpfreaks.com/topic/83017-file-output/#findComment-422451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.