help with file downloads from MySQL

help with file downloads from MySQL

am 21.03.2006 19:55:56 von Mickey Martin

Every time I try to download a file from MySQL it cannot be opened. Using
HexEdit, I noticed that all of the files are getting 0a added to the
beginning of them (happens with all browsers).

I can look at the files with MySQL Query Browser and they don't have the 0a.
Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.

Here's what I'm using:
mysql_select_db($database_ctnwww, $ctnwww);
$query_Attachment = sprintf("SELECT bin_data, filetype, filename, filesize
FROM IssueAttach WHERE id_files=%s", $_GET['id_files']);
$Attachment = mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
$row_Attachment = mysql_fetch_array($Attachment);

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

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

Thanks in advance,
Mickey

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 21.03.2006 21:07:00 von Bastien Koert

If you load the data into the field with addslashes, have you tried
stripslashes on the way out?

Bastien


>From: "Mickey Martin"
>To: php-db@lists.php.net
>Subject: [PHP-DB] help with file downloads from MySQL
>Date: Tue, 21 Mar 2006 12:55:56 -0600
>
>Every time I try to download a file from MySQL it cannot be opened. Using
>HexEdit, I noticed that all of the files are getting 0a added to the
>beginning of them (happens with all browsers).
>
>I can look at the files with MySQL Query Browser and they don't have the
>0a.
>Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.
>
>Here's what I'm using:
>mysql_select_db($database_ctnwww, $ctnwww);
>$query_Attachment = sprintf("SELECT bin_data, filetype, filename, filesize
>FROM IssueAttach WHERE id_files=%s", $_GET['id_files']);
>$Attachment = mysql_query($query_Attachment, $ctnwww) or
>die(mysql_error());
>$row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: PHP Generated Data");
> echo $data;
>
>Thanks in advance,
>Mickey
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 21.03.2006 21:14:53 von Mickey Martin

Stripslashes causes the download to hang. I've also tried with base64_encode
on the upload and base64_decode on the download with the same results.



-----Original Message-----
From: Bastien Koert [mailto:bastien_k@hotmail.com]
Sent: Tuesday, March 21, 2006 2:07 PM
To: mickey.martin@alcatel.com; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

If you load the data into the field with addslashes, have you tried
stripslashes on the way out?

Bastien


>From: "Mickey Martin"
>To: php-db@lists.php.net
>Subject: [PHP-DB] help with file downloads from MySQL
>Date: Tue, 21 Mar 2006 12:55:56 -0600
>
>Every time I try to download a file from MySQL it cannot be opened.
>Using HexEdit, I noticed that all of the files are getting 0a added to
>the beginning of them (happens with all browsers).
>
>I can look at the files with MySQL Query Browser and they don't have
>the 0a.
>Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.
>
>Here's what I'm using:
>mysql_select_db($database_ctnwww, $ctnwww); $query_Attachment =
>sprintf("SELECT bin_data, filetype, filename, filesize FROM IssueAttach
>WHERE id_files=%s", $_GET['id_files']); $Attachment =
>mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
>$row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: PHP Generated Data");
> echo $data;
>
>Thanks in advance,
>Mickey
>
>--
>PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
>http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 21.03.2006 21:18:49 von Mickey Martin

Here's the code I'm using to upload if it helps:

if ($action == "upload") {
include "open_db.inc";

if (isset($binFile) && $binFile != "none") {
$data = addslashes(fread(fopen($binFile, "rb"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(description, bin_data, filename, filesize, filetype) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
$result = mysql_query($sql, $db);
mysql_free_result($result);
echo "The new file was successfully added to the database.

";
echo "";
}
mysql_close();

} else {
?>



-----Original Message-----
From: Bastien Koert [mailto:bastien_k@hotmail.com]
Sent: Tuesday, March 21, 2006 2:07 PM
To: mickey.martin@alcatel.com; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

If you load the data into the field with addslashes, have you tried
stripslashes on the way out?

Bastien


>From: "Mickey Martin"
>To: php-db@lists.php.net
>Subject: [PHP-DB] help with file downloads from MySQL
>Date: Tue, 21 Mar 2006 12:55:56 -0600
>
>Every time I try to download a file from MySQL it cannot be opened.
>Using HexEdit, I noticed that all of the files are getting 0a added to
>the beginning of them (happens with all browsers).
>
>I can look at the files with MySQL Query Browser and they don't have
>the 0a.
>Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.
>
>Here's what I'm using:
>mysql_select_db($database_ctnwww, $ctnwww); $query_Attachment =
>sprintf("SELECT bin_data, filetype, filename, filesize FROM IssueAttach
>WHERE id_files=%s", $_GET['id_files']); $Attachment =
>mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
>$row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: PHP Generated Data");
> echo $data;
>
>Thanks in advance,
>Mickey
>
>--
>PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
>http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 21.03.2006 22:05:14 von Mickey Martin

I tried purposely corrupting the file by adding blank spaces at the
beginning of the echo:
echo " ",$data;

The 0a was put in at the beginning again, followed by the spaces and then
the file.

Mickey


-----Original Message-----
From: Bastien Koert [mailto:bastien_k@hotmail.com]
Sent: Tuesday, March 21, 2006 2:07 PM
To: mickey.martin@alcatel.com; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

If you load the data into the field with addslashes, have you tried
stripslashes on the way out?

Bastien


>From: "Mickey Martin"
>To: php-db@lists.php.net
>Subject: [PHP-DB] help with file downloads from MySQL
>Date: Tue, 21 Mar 2006 12:55:56 -0600
>
>Every time I try to download a file from MySQL it cannot be opened.
>Using HexEdit, I noticed that all of the files are getting 0a added to
>the beginning of them (happens with all browsers).
>
>I can look at the files with MySQL Query Browser and they don't have
>the 0a.
>Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.
>
>Here's what I'm using:
>mysql_select_db($database_ctnwww, $ctnwww); $query_Attachment =
>sprintf("SELECT bin_data, filetype, filename, filesize FROM IssueAttach
>WHERE id_files=%s", $_GET['id_files']); $Attachment =
>mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
>$row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: PHP Generated Data");
> echo $data;
>
>Thanks in advance,
>Mickey
>
>--
>PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
>http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 21.03.2006 22:49:44 von Giff Hammar

Can you use something like this (I haven't tried it)?

$search = '/^0a/'; // Looks at the beginning of the stream for 0a
$replace = ""; // Replace with this
$limit = 1; // How many you want to do
$new_file = preg_replace($search, $replace, $old_file, $limit);

Giff

-----Original Message-----
From: Mickey Martin [mailto:Mickey.Martin@alcatel.com]
Sent: Tuesday, March 21, 2006 4:05 PM
To: 'Bastien Koert'; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

I tried purposely corrupting the file by adding blank spaces at the
beginning of the echo:
echo " ",$data;

The 0a was put in at the beginning again, followed by the spaces and then
the file.

Mickey


-----Original Message-----
From: Bastien Koert [mailto:bastien_k@hotmail.com]
Sent: Tuesday, March 21, 2006 2:07 PM
To: mickey.martin@alcatel.com; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

If you load the data into the field with addslashes, have you tried
stripslashes on the way out?

Bastien


>From: "Mickey Martin"
>To: php-db@lists.php.net
>Subject: [PHP-DB] help with file downloads from MySQL
>Date: Tue, 21 Mar 2006 12:55:56 -0600
>
>Every time I try to download a file from MySQL it cannot be opened.
>Using HexEdit, I noticed that all of the files are getting 0a added to
>the beginning of them (happens with all browsers).
>
>I can look at the files with MySQL Query Browser and they don't have
>the 0a.
>Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.
>
>Here's what I'm using:
>mysql_select_db($database_ctnwww, $ctnwww); $query_Attachment =
>sprintf("SELECT bin_data, filetype, filename, filesize FROM IssueAttach
>WHERE id_files=%s", $_GET['id_files']); $Attachment =
>mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
>$row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: PHP Generated Data");
> echo $data;
>
>Thanks in advance,
>Mickey
>
>--
>PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
>http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 22.03.2006 16:08:45 von Mickey Martin

From what I can tell, the 0a is not in the file, but is being inserted
either with the echo or by the browser when it receives the file. Does
anyone know if a proxy server would cause this? There shouldn't be one
involved, but I am going to contact my IT department to find out how it is
configured today.

Thanks,
Mickey

-----Original Message-----
From: Giff Hammar [mailto:ghammar@certifiedparts.com]
Sent: Tuesday, March 21, 2006 3:50 PM
To: 'Mickey Martin'; 'Bastien Koert'; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

Can you use something like this (I haven't tried it)?

$search = '/^0a/'; // Looks at the beginning of the stream for 0a $replace =
""; // Replace with this $limit = 1; // How many you want to do $new_file =
preg_replace($search, $replace, $old_file, $limit);

Giff

-----Original Message-----
From: Mickey Martin [mailto:Mickey.Martin@alcatel.com]
Sent: Tuesday, March 21, 2006 4:05 PM
To: 'Bastien Koert'; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

I tried purposely corrupting the file by adding blank spaces at the
beginning of the echo:
echo " ",$data;

The 0a was put in at the beginning again, followed by the spaces and then
the file.

Mickey


-----Original Message-----
From: Bastien Koert [mailto:bastien_k@hotmail.com]
Sent: Tuesday, March 21, 2006 2:07 PM
To: mickey.martin@alcatel.com; php-db@lists.php.net
Subject: RE: [PHP-DB] help with file downloads from MySQL

If you load the data into the field with addslashes, have you tried
stripslashes on the way out?

Bastien


>From: "Mickey Martin"
>To: php-db@lists.php.net
>Subject: [PHP-DB] help with file downloads from MySQL
>Date: Tue, 21 Mar 2006 12:55:56 -0600
>
>Every time I try to download a file from MySQL it cannot be opened.
>Using HexEdit, I noticed that all of the files are getting 0a added to
>the beginning of them (happens with all browsers).
>
>I can look at the files with MySQL Query Browser and they don't have
>the 0a.
>Using php 4.3.11, Solaris 8, Apache 2.0.54, MySQL 4.1.11.
>
>Here's what I'm using:
>mysql_select_db($database_ctnwww, $ctnwww); $query_Attachment =
>sprintf("SELECT bin_data, filetype, filename, filesize FROM IssueAttach
>WHERE id_files=%s", $_GET['id_files']); $Attachment =
>mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
>$row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: PHP Generated Data");
> echo $data;
>
>Thanks in advance,
>Mickey
>
>--
>PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
>http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 24.03.2006 21:53:17 von Mickey Martin

I guessed that 0a is the code for a new line, but cannot find where it is in
my code. This is the entire code that I'm using for the download:

if ($id_files) {

mysql_select_db($database_ctnwww, $ctnwww);
$query_Attachment = sprintf("SELECT bin_data, filetype, filename, filesize
FROM IssueAttach WHERE id_files=%s", $_GET['id_files']);
$Attachment = mysql_query($query_Attachment, $ctnwww) or die(mysql_error());
$row_Attachment = mysql_fetch_array($Attachment);

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

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

I have also tried putting a string in front of the file on the echo line:
echo "TEST TEXT", $data;

When the file is saved, it begins with 0a followed by TEST TEXT and then the
start of the file without another instance of 0a.

Mickey


-----Original Message-----
From: Oskar [mailto:oki2003@volny.cz]
Sent: Friday, March 24, 2006 1:59 AM
To: Mickey Martin; PHP db
Subject: Re: [PHP-DB] help with file downloads from MySQL

Mickey Martin wrote:

> From what I can tell, the 0a is not in the file, but is being inserted
>either with the echo or by the browser when it receives the file. Does
>anyone know if a proxy server would cause this? There shouldn't be one
>involved, but I am going to contact my IT department to find out how it
>is configured today.
>
>Thanks,
>Mickey
>
>
>
>
>
0a is new line character code. Check your script you must be somewhere
displaying it.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 25.03.2006 03:02:46 von robleyd

Mickey Martin wrote:

> I guessed that 0a is the code for a new line, but cannot find where it is
> in my code. This is the entire code that I'm using for the download:
>
> > if ($id_files) {
>
> mysql_select_db($database_ctnwww, $ctnwww);
> $query_Attachment = sprintf("SELECT bin_data, filetype, filename, filesize
> FROM IssueAttach WHERE id_files=%s", $_GET['id_files']);
> $Attachment = mysql_query($query_Attachment, $ctnwww) or
> die(mysql_error()); $row_Attachment = mysql_fetch_array($Attachment);
>
> $data = $row_Attachment['bin_data'];
> $name = $row_Attachment['filename'];
> $size = $row_Attachment['filesize'];
> $type = $row_Attachment['filetype'];
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=\"$name\"");
> header("Content-Description: PHP Generated Data");
> echo $data;
> }
> ?>
>
> I have also tried putting a string in front of the file on the echo line:
> echo "TEST TEXT", $data;
>
> When the file is saved, it begins with 0a followed by TEST TEXT and then
> the start of the file without another instance of 0a.
>
> Mickey
>
>
> -----Original Message-----
> From: Oskar [mailto:oki2003@volny.cz]
> Sent: Friday, March 24, 2006 1:59 AM
> To: Mickey Martin; PHP db
> Subject: Re: [PHP-DB] help with file downloads from MySQL
>
> Mickey Martin wrote:
>
>> From what I can tell, the 0a is not in the file, but is being inserted
>>either with the echo or by the browser when it receives the file. Does
>>anyone know if a proxy server would cause this? There shouldn't be one
>>involved, but I am going to contact my IT department to find out how it
>>is configured today.
>>
>>Thanks,
>>Mickey
>>
>>
>>
>>
>>
> 0a is new line character code. Check your script you must be somewhere
> displaying it.

For a wild guess - is empty line above it, that could cause the extra EOL character.



Cheers
--
David Robley

My other car is a broom!
Today is Prickle-Prickle, the 11st day of Discord in the YOLD 3172

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: help with file downloads from MySQL

am 28.03.2006 17:01:58 von Mickey Martin

I found the problem. I had 2 separate PHP sections of code with a blank line
between them. For some reason, the blank line was causing the newline to be
outputted before the file. I found it by accidentally putting a blank space
between the sections that output the file and the free the results from the
queries and it put a newline at the end of the output data.

Thanks everyone for the help with this.

-----Original Message-----
From: Oskar [mailto:oki2003@volny.cz]
Sent: Friday, March 24, 2006 1:59 AM
To: Mickey Martin; PHP db
Subject: Re: [PHP-DB] help with file downloads from MySQL

Mickey Martin wrote:

> From what I can tell, the 0a is not in the file, but is being inserted
>either with the echo or by the browser when it receives the file. Does
>anyone know if a proxy server would cause this? There shouldn't be one
>involved, but I am going to contact my IT department to find out how it
>is configured today.
>
>Thanks,
>Mickey
>
>
>
>
>
0a is new line character code. Check your script you must be somewhere
displaying it.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php