readfile文件下载有关问题,如有有效解决方法,加分结贴

WBOY
Release: 2016-06-13 13:45:23
Original
903 people have browsed it

readfile文件下载问题,如有有效解决办法,加分结贴
大家好,现在我们的项目遇到了一个比较困扰的问题。使用readfile下载图片文件时,文件会文件首会比原来多出一位(0x0A)来,使用UEdit删除文件首的那个16进制位文件可正确读出。

源代码如下:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->

<?php $file = 'test_img.bmp';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>



Copy after login



下载后的文件和原文件比较如下:


代码在以前的服务器上运行从未出现问题,但当我们的项目更换了运行支撑环境(操作系统/apache/php 版本均有可能不同),在网上查遍了所有的文档,无解决办法。求高手解决此问题,在此先感谢大家了!

如有有效解决办法,将给您加分结贴。


------解决方案--------------------
楼上广告。。。

readfile读取的文件里是否有这个0a呢?
------解决方案--------------------
那既然知道,多出的字符串,就截取掉就好啦
------解决方案--------------------
0a-换行符号-"\n";看下你们那个读取文件的编码是不是gbk的,有些文件含有bom头,建议看可否改为utf-8格式的;你看你们的读取文件里是否有换行符号;或者对读取的内容直接trim()一下呢
------解决方案--------------------
探讨

0a-换行符号-"\n";看下你们那个读取文件的编码是不是gbk的,有些文件含有bom头,建议看可否改为utf-8格式的;你看你们的读取文件里是否有换行符号;或者对读取的内容直接trim()一下呢
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!