php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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'); ?>

<?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;
  
?>


<?php
mysql_free_result($DnldFile);
?>

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'); ?>

<?php
$colname_DnldFile = "-1";

...

?>


<?php
mysql_free_result($DnldFile);
?>

causes the proper file to output.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 14:01:29 2024 UTC