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发起的请求
收藏文章
热评话题
- Android定时器实现的几种方式整理及removeCallbacks失效问题解决_Android开发_龙盟编程网
- 在linux中导入sql文件的方法分享(使用命令行转移mysql数据库)_MySQL 技术_龙盟编程网
- 如何应用PHP函数imagettftext处理图片_php编程_个人技术分享
- 如何解决C语言,函数名与宏冲突_C/C++开发_龙盟编程网
- 查询反向链接中link和domain的区别_SEO优化_龙盟编程网
- sql 查询本年、本月、本日记录的语句,附SQL日期函数_Sql Server开发_龙盟编程网
- 在ASP.Net中应用Javascript_Javascript编程_龙盟编程网
精彩图集
精彩文章