开发者

Serving css images with PHP from outside public folder

I have a css file that links to images.

.test{
  background: url(http://site.com/dynamic/test.jpg) no-repeat;
}

These images however are dynamic. They change by the minute so I have to generate them and serve them with php. This means I don't save them to the public folder. I just serve them directly from the php script.

The problem is when I visit the php script (http://site.com/dynamic/test.jpg), it generates the image correctly and I can see it in the browser, but when the same url is used in the css file as I need, the css can't seem to access the images.

I think it's because the image isn't saved in the public folder and is delivered by php which means that image has to be directly called to be generated, and calling the css file doesn't actually 开发者_JAVA技巧hit the php script (image url).

Does anyone have ideas to solve this problem?


Try to return Content-type using php header function

header("Content-type: application/force-download"); 
header('Content-Type: application/octet-stream'); 
header('Content-Type: image/jpeg'); // or png...


First of all you should ask your own system what's going on, not people who have no idea nor access to your site.

Use some HTTP sniffer to see which exactly HTTP requests being sent and which responses returned. LiveHTTPHeader or firebug addons for Firefox or whatever of the kind can be used.

Then compare these headers with ones you get requesting this image directly.
Then you may ask your question here, providing these headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜