473,791 Members | 2,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help! Streaming files via PHP get truncated...

Hi there folks

I've got an interesting little problem going on. On one of my projects,
I have users log in to retrieve files. The files themselves are stored
outside of the www directory on the server, so the only way they can be
downloaded is for PHP to stream them to the user.

My problem is that my downloads are always "completing " too soon, and
always around 1.6 -> 1.9 MB. So, when I try to download a 50MB file,
I'm told that the download is complete wayyy to early, and of course, the
file is nothing but garbage.

I have another script on the same server that will zip together a bunch
of files on the fly and stream it to the browser using a class that i did
not write personally. If I tell my system I want to download that 50MB
file as a .zip file, it works without a problem. If I tell the system I
want to download the 50MB file normally (its a PDF) using my
'stream.php' file, it truncates. ACK!

some variables that I got from phpInfo(); which may/may not have anything
to do with this problem (maybe this will help someone/me?):

output_bufferin g 4096 4096
max_execution_t ime 210 210
max_input_time 120 120

Anyways, here's the essence of the script I'm using - it's worked on
other servers (where i've been able to download large files
successfully).. .. can anyone offer any suggestions as to why the
downloads are truncating? or any other methods of doing what I want to
do?

thanks. try to ignore the word-wrap! oh... PHP Version 5.0.4
(www.entropy.ch Release 1) on a Mac PPC, running apache.

*******

<?php
session_cache_l imiter("must-revalidate");
session_start() ;

/* downloading a file */

@$vKey = addslashes($_RE QUEST['vKey']);

if ($vKey=="") { //no ID?
popup("We are having trouble locating this specific file.",$vBackPa ge);
exit;
}

databaseconnect (); //custom function connects to the database

//get the file
$row = singlequery("SE LECT f.FilePath,f.Fi leName FROM Files AS f INNER
JOIN Folders ON f.FolderID = Folders.FolderI D INNER JOIN Projects ON
Folders.Project ID = Projects.Projec tID WHERE f.FileKey='$vKe y'");
}

$vFileName = $row["FileName"];
$vFilePath = $row["FilePath"];

if($vFileName== "") {
popup("The file does not exist, or you do not have access to it.",
$vBackPage);
}

//now we stream the file, prompting a download
header("Cache-control: private");

// We'll be outputting a file
header('Content-Type: application/octet-stream');

// It will be called whatever the file name is called, and given the
// attachment Disposition to force the download

header('Content-Disposition: attachment; filename="'.$vF ileName.'"');

// The source... see ya
readfile($vFile Path);

?>
many thanks,
GM
Jan 27 '06 #1
2 3577
Good Man <he***@letsgo.c om> wrote in
news:Xn******** *************** *@216.196.97.13 1:

My problem is that my downloads are always "completing " too soon, and
always around 1.6 -> 1.9 MB.


hey, guess who JUST read the readfile(); page in the manual? ;)

Down in the comments section are the following posts... I've posted them
here in case anyone is trying to solve this problem in the future and
stumbled across this thread (hello future! do you have flying cars?)
COMMENTS:
( http://ca.php.net/manual/en/function.readfile.php )

flobee at gmail dot com
06-May-2005 02:17
regarding php5:
i found out that there is already a disscussion @php-dev about readfile
() and fpassthru() where only exactly 2 MB will be delivered. so you may
use this on php5 to get lager files

.... which eventually morphed via 'chrisputnam at gmai<snip>' into the
following function, which i have used successfully. thanks chris!
function readfile_chunke d($filename,$re tbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename , 'rb');
$handle = fopen($filename , 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle) ) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer) ;
}
}
$status = fclose($handle) ;
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;

}

Jan 27 '06 #2
d
"Good Man" <he***@letsgo.c om> wrote in message
news:Xn******** *************** *@216.196.97.13 1...
Good Man <he***@letsgo.c om> wrote in
news:Xn******** *************** *@216.196.97.13 1:

My problem is that my downloads are always "completing " too soon, and
always around 1.6 -> 1.9 MB.
hey, guess who JUST read the readfile(); page in the manual? ;)

Down in the comments section are the following posts... I've posted them
here in case anyone is trying to solve this problem in the future and
stumbled across this thread (hello future! do you have flying cars?)


Nicely done ;)

COMMENTS:
( http://ca.php.net/manual/en/function.readfile.php )

flobee at gmail dot com
06-May-2005 02:17
regarding php5:
i found out that there is already a disscussion @php-dev about readfile
() and fpassthru() where only exactly 2 MB will be delivered. so you may
use this on php5 to get lager files

... which eventually morphed via 'chrisputnam at gmai<snip>' into the
following function, which i have used successfully. thanks chris!
function readfile_chunke d($filename,$re tbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename , 'rb');
$handle = fopen($filename , 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle) ) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer) ;
}
}
$status = fclose($handle) ;
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;

}

Jan 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6561
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
4
3357
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
0
568
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if link doesn't work, basically here is the article: An Exploration Into Launching Context-Sensitive HTML Help with Topic IDs in VB.NET I spent this evening investigating the HTML Help API as implemented in
4
2638
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then type in a command line that runs the help in the correct Context from a button on each form. It all worked fine - HERE. The problem is that when I sent it out to a site, the help file was not able to be accessed because it was my path in the...
5
3281
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
4
2257
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! Apparently, all I have to do is create a "Help Project"! There's my starting point. So the VS help says: "To create a Help project, click on the File menu, choose New and follow the wizard's instructions"
3
2033
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So far so good - when I press F1, I get HTML Help popping up with my Help file. This is good but I've been requested to make Help pop up when the user clicks on "Help" in the menu, or on a specific Help Button. I'm trying to trigger the HelpRequested...
10
3368
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
1
6140
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
2895
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.