473,837 Members | 1,696 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 3580
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
6576
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
3359
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
2644
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
3294
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
2261
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
2037
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
3377
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
6149
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
2902
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
9846
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
10883
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
10579
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
10633
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
10276
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5852
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
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
4050
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.