我有一个从数据库返回图像的函数,图像在数据库中100%正常,但是当它被发送到浏览器时,一开始就会插入一个换行符(返回),它会破坏文件。
返回文件的代码是:
//if(ob_get_length() > 0)
//{
//ob_clean();
//}
如上所述,当它取消注释时,它甚至不让浏览器下载文件。
function header_file($data, $file_data)
{
$last_modified = gmdate('D, d M Y H:i:s', $file_data['unix_last_modified_time'])." GMT";
// update the accessed record
$GLOBALS['db']->query("update file_uploads set file_upload_accessed_count = file_upload_accessed_count + 1 where file_upload_id = '".$GLOBALS['id']."'");
// if browser question if it's up to date
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
{
// parse header
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
if ($if_modified_since == $last_modified)
{
// the browser's cache is still up to date
header("HTTP/1.0 304 Not Modified");
header("Cache-Control: max-age=86400, must-revalidate");
exit;
}
}
header("Cache-Control: max-age=86400, must-revalidate");
header("Last-Modified: ".$last_modified);
header("Content-Type: ".$file_data['file_upload_type']);
if($file_data['file_upload_type'] == 'application/x-shockwave-flash')
header("Content-Disposition: inline; filename=\"".str_replace(' ','_',$file_data['file_upload_name'])."\"");
else
header("Content-Disposition: attachment; filename=\"".str_replace(' ','_',$file_data['file_upload_name'])."\"");
// send data to output
echo $data;
exit;
}
相关问题: Corrupted File from PHP Header File returned from database? https://stackoverflow.com/questions/19768650/zend-caching-of-images-gives-problems-once-the-site-goes-down-for-a-while
答案 0 :(得分:0)
我会做以下事情。你的PHP文件中有一个额外的空间。
找到它可能有点棘手,所以开始放一些
echo "here"
在您的代码中以查看在echo之前或之后是否找到此换行符。继续向上或向下移动文件,直到你可以看到文件的位置(它可能在包含文件中,因此你必须追踪它。
---------------文件开头