Jump to content

Archived

This topic is now archived and is closed to further replies.

dptr1988

Sending with type application/binary only downloads 24,576 bytes

Recommended Posts

I made a php script for sending a file but it only sends the first 24,576 bytes. This is the code:

[code]
header('Content-type:  application/binary');
header('Content-Disposition: attachment; filename='.$_GET['fname']);
readfile($filedir.$_GET['fname']);
[/code]

Then run the script with "send_file.php?fname=filename.jpg" and everything is normal except that the file is limited to 24,576 bytes. Do I need to change a setting in my php.ini?
Thanks

Share this post


Link to post
Share on other sites
Try to send a Content-Length header:

[code]$size = filesize($filedir . $_GET['fname']);
header('Content-Length: ' . $size);[/code]

Share this post


Link to post
Share on other sites
I sent the Content-Length header and now the files are the right size. But now there is garbage in the files. I made a file full of zeros and tried downloading it and there are a whole lot of other numbers besides zero. And it's not readable text or anything that looks good. It just looks like random numbers. Am I useing the wrong content type for a binary file?

BTW here's the way I'm sending the Content-Length header:
[code]
header('Content-Length: '.filesize($filedir.$_GET['fname']));
[/code]

Thanks

Share this post


Link to post
Share on other sites
readfile() was sending NTFS stuff. So I replaced it with fopen() fread() print() and now it works. Thanks poirot for helping me with my headers!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.