471,089 Members | 1,094 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Problem downloading binary data

Hi all

I have this script(download.php) which downloads binary data from a
mysql database.

<?

/* SNIP */

$document=document::singleton();
$doc=$document->get_document($id);

if (is_object($doc)){
die;
}

header("Content-type: $doc[type]");
header("Content-length: $doc[size]");
header("Content-Disposition: attachment; filename=$doc[name]");

echo($doc['content']);

exit;

?>

This is called from another page in the
<a href="download.php?id=4">CLick here to download</a>
fashion.

The problem I am experiencing is that the download stop on 64k and then
the files are obviously corrupted.

I have checked that I do have the correct size in the db and I am giving
the correct size in the Content-length header.

Thanks
Barry
Jan 25 '06 #1
6 1514
Barry wrote:
Hi all

I have this script(download.php) which downloads binary data from a
mysql database.

<?

/* SNIP */

$document=document::singleton();
$doc=$document->get_document($id);

if (is_object($doc)){
die;
}
So if $doc is an object you die?

Is that what you want?
I would expect:
if (is_object($doc)){
echo "\doc is not an object!";
exit;
}

Regards,
Erwin Moller

header("Content-type: $doc[type]");
header("Content-length: $doc[size]");
header("Content-Disposition: attachment; filename=$doc[name]");

echo($doc['content']);

exit;

?>

This is called from another page in the
<a href="download.php?id=4">CLick here to download</a>
fashion.

The problem I am experiencing is that the download stop on 64k and then
the files are obviously corrupted.

I have checked that I do have the correct size in the db and I am giving
the correct size in the Content-length header.

Thanks
Barry


Jan 25 '06 #2
>
if (is_object($doc)){
Now I make the same mistake:
Should be of course:
if (!is_object($doc)){
echo "\doc is not an object!";
exit;
} echo "\doc is not an object!";
exit;
}

Regards,
Erwin Moller

Jan 25 '06 #3
Erwin Moller wrote:
Barry wrote:

Hi all

I have this script(download.php) which downloads binary data from a
mysql database.

<?

/* SNIP */

$document=document::singleton();
$doc=$document->get_document($id);

if (is_object($doc)){
die;
}

So if $doc is an object you die?

Is that what you want?
I would expect:
if (is_object($doc)){
echo "\doc is not an object!";
exit;
}

Regards,
Erwin Moller


Yes I want it to die.
The function returns an error object if it fails.
This means that an error has occured and then I just die.

If the function returns an array, its found the data.

This all works for files less than 64k.
Its only with larger files that the download stops at 64k.
This is weird bahavior, I think it might be some config on the server.

Thanks
Barry
header("Content-type: $doc[type]");
header("Content-length: $doc[size]");
header("Content-Disposition: attachment; filename=$doc[name]");

echo($doc['content']);

exit;

?>

This is called from another page in the
<a href="download.php?id=4">CLick here to download</a>
fashion.

The problem I am experiencing is that the download stop on 64k and then
the files are obviously corrupted.

I have checked that I do have the correct size in the db and I am giving
the correct size in the Content-length header.

Thanks
Barry


Jan 25 '06 #4
Barry wrote:
Erwin Moller wrote:
Barry wrote:

Hi all

I have this script(download.php) which downloads binary data from a
mysql database.

<?

/* SNIP */

$document=document::singleton();
$doc=$document->get_document($id);

if (is_object($doc)){
die;
}

So if $doc is an object you die?

Is that what you want?
I would expect:
if (is_object($doc)){
echo "\doc is not an object!";
exit;
}

Regards,
Erwin Moller


Yes I want it to die.
The function returns an error object if it fails.
This means that an error has occured and then I just die.

If the function returns an array, its found the data.

This all works for files less than 64k.
Its only with larger files that the download stops at 64k.
This is weird bahavior, I think it might be some config on the server.


Hmm, ok.

Strange.
Are you sure your document-singleton is actually delivering the right stuff?
I mean: the problem could arise earlier than at the moment of delivery.
And 64K sounds very suspect.

I would check that part first, just spit out :

echo htmlentities($doc['content']);

Well, that is all I can think of.

Good luck.

Regards,
Erwin Moller

Thanks
Barry
header("Content-type: $doc[type]");
header("Content-length: $doc[size]");
header("Content-Disposition: attachment; filename=$doc[name]");

echo($doc['content']);

exit;

?>

This is called from another page in the
<a href="download.php?id=4">CLick here to download</a>
fashion.

The problem I am experiencing is that the download stop on 64k and then
the files are obviously corrupted.

I have checked that I do have the correct size in the db and I am giving
the correct size in the Content-length header.

Thanks
Barry



Jan 25 '06 #5
Erwin Moller wrote:
Barry wrote:

Erwin Moller wrote:
Barry wrote:

Hi all

I have this script(download.php) which downloads binary data from a
mysql database.

<?

/* SNIP */

$document=document::singleton();
$doc=$document->get_document($id);

if (is_object($doc)){
die;
}
So if $doc is an object you die?

Is that what you want?
I would expect:
if (is_object($doc)){
echo "\doc is not an object!";
exit;
}

Regards,
Erwin Moller


Yes I want it to die.
The function returns an error object if it fails.
This means that an error has occured and then I just die.

If the function returns an array, its found the data.

This all works for files less than 64k.
Its only with larger files that the download stops at 64k.
This is weird bahavior, I think it might be some config on the server.

Hmm, ok.

Strange.
Are you sure your document-singleton is actually delivering the right stuff?
I mean: the problem could arise earlier than at the moment of delivery.
And 64K sounds very suspect.

I would check that part first, just spit out :

echo htmlentities($doc['content']);

Well, that is all I can think of.

Good luck.

Regards,
Erwin Moller


thanks for the help.
yes, I get the correct data.
when I dump the array all is there.

also, docs and images below 64k work fine.

strange one this.
Thanks
Barry

header("Content-type: $doc[type]");
header("Content-length: $doc[size]");
header("Content-Disposition: attachment; filename=$doc[name]");

echo($doc['content']);

exit;

?>

This is called from another page in the
<a href="download.php?id=4">CLick here to download</a>
fashion.

The problem I am experiencing is that the download stop on 64k and then
the files are obviously corrupted.

I have checked that I do have the correct size in the db and I am giving
the correct size in the Content-length header.

Thanks
Barry

Jan 25 '06 #6
I have seen cutoff problems in other posts in trying to use fread() with
chunks larger than about 8K.
is that what you are using in your method?

"Barry" <b@b.com> wrote in message news:dr**********@ctb-nnrp2.saix.net...
Erwin Moller wrote:
Barry wrote:

Erwin Moller wrote:

Barry wrote:

>Hi all
>
>I have this script(download.php) which downloads binary data from a
>mysql database.
>
><?
>
>/* SNIP */
>
>$document=document::singleton();
>$doc=$document->get_document($id);
>
>if (is_object($doc)){
>die;
>}
So if $doc is an object you die?

Is that what you want?
I would expect:
if (is_object($doc)){
echo "\doc is not an object!";
exit;
}

Regards,
Erwin Moller

Yes I want it to die.
The function returns an error object if it fails.
This means that an error has occured and then I just die.

If the function returns an array, its found the data.

This all works for files less than 64k.
Its only with larger files that the download stops at 64k.
This is weird bahavior, I think it might be some config on the server.

Hmm, ok.

Strange.
Are you sure your document-singleton is actually delivering the right
stuff?
I mean: the problem could arise earlier than at the moment of delivery.
And 64K sounds very suspect.

I would check that part first, just spit out :

echo htmlentities($doc['content']);

Well, that is all I can think of.

Good luck.

Regards,
Erwin Moller


thanks for the help.
yes, I get the correct data.
when I dump the array all is there.

also, docs and images below 64k work fine.

strange one this.
Thanks
Barry
>header("Content-type: $doc[type]");
>header("Content-length: $doc[size]");
>header("Content-Disposition: attachment; filename=$doc[name]");
>
>echo($doc['content']);
>
>exit;
>
>?>
>
>This is called from another page in the
><a href="download.php?id=4">CLick here to download</a>
>fashion.
>
>The problem I am experiencing is that the download stop on 64k and then
>the files are obviously corrupted.
>
>I have checked that I do have the correct size in the db and I am
>giving
>the correct size in the Content-length header.
>
>Thanks
>Barry

Feb 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Kubaton Lover | last post: by
1 post views Thread by NewFilmFan | last post: by
11 posts views Thread by Abhishek | last post: by
3 posts views Thread by John R. Delaney | last post: by
15 posts views Thread by =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post: by
1 post views Thread by Muddasir | last post: by
4 posts views Thread by Xavier | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.