|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36894 blank lines between php sections output in echo of binary data from MySQL
Submitted: 2006-03-28 17:20 UTC Modified: 2006-03-28 17:25 UTC
From: mickey dot martin at alcatel dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.1.2 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mickey dot martin at alcatel dot com
New email:
PHP Version: OS:


 [2006-03-28 17:20 UTC] mickey dot martin at alcatel dot com
When outputting a binary data file from MySQL, erronious newlines are being inserted into the file when there are multiple sections of php code (in seperate php tags) and there are blank spaces in between the sections.

Reproduce code:
<?php require_once('../Connections/TestFiles.php'); ?>

$colname_DnldFile = "-1";
if (isset($_GET['id_files'])) {
  $colname_DnldFile = (get_magic_quotes_gpc()) ? $_GET['id_files'] : addslashes($_GET['id_files']);
mysql_select_db($database_TestFiles, $TestFiles);
$query_DnldFile = sprintf("SELECT bin_data, filename, filesize, filetype FROM tbl_files WHERE id_files = %s", $colname_DnldFile);
$DnldFile = mysql_query($query_DnldFile, $TestFiles) or die(mysql_error());
$row_DnldFile = mysql_fetch_assoc($DnldFile);
$totalRows_DnldFile = mysql_num_rows($DnldFile);

  $type = $row_DnldFile['filetype'];
  $name = $row_DnldFile['filename'];
  $data = $row_DnldFile['bin_data'];
  $size = $row_DnldFile['filesize']; 

  header("Content-type: $type");
  header("Content-length: $size");
  header("Content-Disposition: attachment; filename=\"$name\"");
  header("Content-Description: PHP Generated Data");
  echo $data;


Expected result:
I expect to download the file from MySQL and be able to open and read it in the proper application.

Actual result:
When executing this code with a plain text file, a blank line is being inserted at the beginning and end of the file. When executing with a binary file (MS Word document) the file is un-readable. Removing the line between the php tags:
<?php require_once('../Connections/TestFiles.php'); ?>

$colname_DnldFile = "-1";




causes the proper file to output.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-28 17:25 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 04:05:45 2022 UTC