[PHP] Header to out put the image file.

Assuming that image.jpg exists and is readable by PHP, how will the following script be
displayed if called directly from a browser?

 

<?php
header ("Content-type: image/jpeg");
?>

<?php
readfile ("image.jpg");
?>

 

There are four answers:

A. As a JPEG image
B. As a binary file for display within the browser
C. As a binary file for download
D. As a JPEG file for download
E. As a broken image

 

 What should the result to be? Maybe you would select A as the answer.

But,

 

did you see that blank line between the first code block and the second? That’s going to be sent to the browser as content, thus making the overall binary data of the image corrupt! Therefore, the browser will display a broken image (or a message stating that the image is corrupted).

 

So here the answer is E.

 

Without the blank line between the first code block and the second, the answer is A.

 

 

 

posted @ 2010-05-14 15:30  DavidHHuan  阅读(313)  评论(0编辑  收藏  举报