PHP Download function
I have a form with three fields; Name, Organisation and Email. And a submit button.
When you hit submit, it writes the three things to a database and invokes the download of a file.
This all works as expected, however after a seemingly random length of time (between 3 and 10 minutes) the file stops downloading. No error or timeout messages, just stops as if it has successfully downloaded.
The file is a large exe (360 MB). I presume it is something to do with the PHP.
The code is:
My questions are;
$filename = "myfile.exe";
header("Content-Length: " . filesize($filename));
header('Content-Disposition: attachment; filename=myfile.exe');
1. If I right click on a standard link and 'save file as' it downloads just fine. If the PHP script has done it's job and now the file is downloading, what would the previous PHP have to do with it?
2. What would be the correct code? I have read the manual but it serves only to confuse me mainly because of my limited PHP knowledge I guess.
Thank you so much for any replies!!
readfile() will exhaust memory, you need to send the data to browser in chunks (keeping memory limit down) then it only depends on timelimit.
Look into PEAR HTTP_DOWNLOAD or search for a "readfile chunked" function that includes flushing.
Quick google search for chunked dl returns this which looks like it will suit your needs: http://teddy.fr/2007/11/28/how-serve...s-through-php/
Thank you, Mistin
Originally Posted by mistin.ca
That's a great help and a good place to start.
I'll get cracking.
Serving the file in chunks/blocks may not be the solution. There is a maximum execution time limit for PHP scripts, and your server may not allow a script to run long enough to send a 360MB file, no matter how your script tries to send it.
For files that large, you should probably look into setting up a means of allowing authorized users to directly download the file though a conventional HTML/HTTP link. Try looking for a file management script in one of the script directory sites.
Originally Posted by rtrethewey
I have decided to do just what you suggested. I'm still unsure, but after a long afternoon of research, all signs point to a server / script time issue. I read somewhere that most shared hosting will not allow a script to execute for such a length of time.
I have setup the form to do its thing and then load another page with a standard html link. It works just fine, but just not as sleek as I would of liked it!
Thanks for all your pointers though, guys.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread