Jump to content

[Solved] Problem with Defalte | Content Encoding Error


afshin.m
 Share

Recommended Posts

Hello.I use PHP to Deflate all css in page and save it in disk using this code :

<?php	if(!file_exists("cache/css/".$cssallname.".css")){		$fo=fopen("cache/css/def-".$cssallname.".css","x+");		$cssall1=gzdeflate($cssall,2);		fputs($fo,$cssall1);		fclose($fo);	}?>

I don't have any problem now, but when i want to get this CSS and show to user i get "Content Encoding Error"This is my code:

<?phpif (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') === FALSE) {	echo file_get_contents($css);}else{	header('Content-Encoding: deflate');	echo file_get_contents($css_def);}?>

When i open file with Firefox i see the CSS code for a moment and then i see "Content Encoding Error"When i use IE i see CSS code and no errors can be observed and also with Opera.Note: I wrote this code for JS files and works fine without errors.Is there any solution?

Edited by Afshin
Link to comment
Share on other sites

Could you possibly do the compression on the server (Apache/IIS) level? They will automatically gzip or deflate the file if they can, and won't if they can't. In the case of IIS, there's even a cache, though I'm not sure for Apache. Even if there isn't, the cache savings will be minimal. It just isn't worth it to do compression on the PHP level.

Link to comment
Share on other sites

Could you possibly do the compression on the server (Apache/IIS) level? They will automatically gzip or deflate the file if they can, and won't if they can't. In the case of IIS, there's even a cache, though I'm not sure for Apache. Even if there isn't, the cache savings will be minimal. It just isn't worth it to do compression on the PHP level.
Thanks for your response.No i can, i should use compressing manually.Any solutions?
Link to comment
Share on other sites

You mean you can't use Apache or IIS for this? Why? Can't you contact your host about it?It looks like you may be missing some variables. Where you do define $css, $css_def, $cssallname? Are you by any chance havinng any plain content between "<?php" and "?>"? That may malform the output. Also, any errors in the output? The easiest way to verify that part is to use a tool like Fiddler (see my signature) to inspect the raw output.

Link to comment
Share on other sites

You mean you can't use Apache or IIS for this? Why? Can't you contact your host about it?It looks like you may be missing some variables. Where you do define $css, $css_def, $cssallname? Are you by any chance havinng any plain content between "<?php" and "?>"? That may malform the output. Also, any errors in the output? The easiest way to verify that part is to use a tool like Fiddler (see my signature) to inspect the raw output.
Listen, i use gzdeflate() function in PHP to Deflate an string and save it with fopen() and i can't use .htaccess file for compressing (Apache or IIS modules)
Link to comment
Share on other sites

Hello all.I found problem and fix it, i see "Content Encoding Error" because i have some whitespace at the end of code (After ?>) and this is because i see "Content Encoding Error"!Thanks all. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...