From:             mickey dot martin at alcatel dot com
Operating system: Windows XP
PHP version:      5.1.2
PHP Bug Type:     Output Control
Bug description:  blank lines between php sections output in echo of binary 
data from MySQL

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.

-- 
Edit bug report at http://bugs.php.net/?id=36894&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36894&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36894&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36894&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36894&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36894&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36894&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36894&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36894&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36894&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36894&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36894&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36894&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36894&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36894&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36894&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36894&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36894&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36894&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36894&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36894&r=mysqlcfg

Reply via email to