php设定http头输出非html内容
php设定http头输出非html内容 [代码片段(56行)]
<html>
</head>
<body>
<div align='center'>
<img src='index.php' alt='' title='' style='border: none;' />
</div>
</body>
</html>
<?php
$path = 'myImage.jpg';
try {
if (is_file ($path)){
if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
$f .= fread($file, 1024*8);
}
fclose($file);
}
header ('Content-type: image/jpeg');
print $f;
} else {
throw new exception ('Sorry, file path is not valid.');
}
} catch (exception $e){
$animage = imagecreate (500, 500);
$red = imagecolorallocate ($animage, 255, 0, 0);
$white = imagecolorallocate ($animage, 255, 255, 255);
imagefilledrectangle ($animage, 0, 0, 500, 500, $white);
imagestring ($animage, 4, ((500 - (strlen($e->getmessage()) * imagefontwidth(4))) / 2), 5, $e->getmessage(), $red);
imagejpeg ($animage);
header ('Content-type: image/jpeg');
imagedestroy ($animage);
}
?>
Common File Format Content Types
Content Type Application
application/pdf Adobe Portable Document Format (PDF) types
application/msword Microsoft Word documents
application/excel Microsoft Excel documents
image/gif GIF images
image/png PNG images
application/octet-stream Zip files
text/plain Plain text (text files)
- 上一篇:PHP is_ 函数判断类型
- 下一篇:php检测客户端请求是否是ajax发起的请求
精彩图集
精彩文章






