timmyRS timmyRS - 6 months ago 21
PHP Question

Teamspeak Hostbanner doesn't work with PHP File

My Problem



I'm having a PHP file that should imitate a PNG file by setting Mime-Type.

Thanks to a
.htaccess
script that I have, I can access my "image" in these ways:



and all of them are working well in my browser, but they don't load in Teamspeak




The Answer



It turned out that Cloudflare was protecting the
/img/
folder, so I made a page rule to stop this. And this simple PHP snippet should output everything correctly.

# Generate $im and Stuff
# ...

# Now Output it
http_response_code(200);
$file = "./temp.png";
imagepng($im, $file);
header("Content-type: image/png");
header("Content-Lenght: ".filesize($file));
readfile($file);
exit;

Answer

I'm not sure what you expect to happen, these are the headers being returned:

CF-Cache-Status 
MISS
CF-RAY  
21cddbcc942220ae-LAX
Cache-Control   
no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection  
keep-alive
Content-Encoding    
gzip
Content-Type    
text/html; charset=UTF-8
Date    
Fri, 28 Aug 2015 06:11:24 GMT
Expires 
Thu, 19 Nov 1981 08:52:00 GMT
Pragma  
no-cache
Server  
cloudflare-nginx
Transfer-Encoding   
chunked
Vary    
Accept-Encoding
X-Powered-By    
PHP/5.4.41-0+deb7u1

So first off, you are returning text/html. That is not the proper mime type for a .png image.

Secondarily, your script needs to actually return .png data.

I'm assuming here you plan to create the .png in your script using GD or ImageMagick, but whatever you plan to do, nothing will appear when an image is expected, when you don't actually provide the proper mime type and the proper image data that is expected to follow that mime type.

Setting the mime type at the top of your script is as easy as:

header('Content-type: image/png'); 

You are also going through Cloudflare. You should have Cloudflare turned off until you've debugged things and are sure that the script is operating as expected.

Comments