|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2006-03-28 17:25 UTC] tony2001@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 22:00:01 2025 UTC | 
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.