Reply to Help! Streaming files via PHP get truncated...

Your name:

Reply:


Posted by Good Man on 01/27/06 04:05

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_buffering 4096 4096
max_execution_time 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_limiter("must-revalidate");
session_start();

/* downloading a file */

@$vKey = addslashes($_REQUEST['vKey']);

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

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

//get the file
$row = singlequery("SELECT f.FilePath,f.FileName FROM Files AS f INNER
JOIN Folders ON f.FolderID = Folders.FolderID INNER JOIN Projects ON
Folders.ProjectID = Projects.ProjectID WHERE f.FileKey='$vKey'");
}

$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="'.$vFileName.'"');

// The source... see ya
readfile($vFilePath);

?>


many thanks,
GM

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация