Slight problem downloading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Slight problem downloading

Post by buckit »

My issue is with the actual downloading of the file... the user gets the dialogue to open, save, or cancel. once they click save... it sits there at 99% for about 10 seconds and then says its finished downloading.
I can’t figure out what this delay is about!


here is the entire story of how this all works:

So I have a form to select some options (theform.php)... The form then submits to a 'creation' page that creates a PDF (creator.php) of the users stored data based on the previously selected options. TCPDF then writes the PDF to a file outside the website (website root: /websites/mysite.com, PDF file path: /websites/tmp).

Once it creates the file it executes the following:

Code: Select all

header("location: /theform.php?dl")
Once back to the original page I start the download with the following:

Code: Select all

if(isset($_GET['dl'])){
	$file = TMP_PATH.md5(date('mdYhi').TENANT_ID).".pdf";
	if (file_exists($file)) { 
		header("Content-type: application/pdf"); 
		header("Content-Transfer-Encoding: Binary"); 
		header("Content-length: ".filesize($file)); 
		header("Content-disposition: attachment; filename='BoundBook-".date('m-d-Y').".pdf'"); 
		readfile("$file"); 
		header("location: /index.php?main_page=exporter");
	} else { 
		$error = "Could not find file"; 
	} 

}
quick explanation of file name... The file name is auto generated in creator.php with the following: md5(date('mdYhi').TENANT_ID)
in the code above it predicts the file name with the same action. The only reason to do this is to avoid any injection to download files as well as only allow a file to be downloaded within the minute it was created. There are obvious flaws with this, but this isn’t much of an issue or the subject of this post (but suggestions are welcome).

to get back on track... I’m not sure what’s going it... I have tried computers outside of my office as well as latest versions of IE, Chrome, and Firefox.

any suggestions?
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: Slight problem downloading

Post by liljester »

so does the file successfully download?
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Slight problem downloading

Post by buckit »

liljester wrote:so does the file successfully download?
yes... works every time... so really its not much of an issue... am just worried about 'happy clickers' thinking that it isnt doing anything and start clicking on anything they can.

I dissable to the submit button once its clicked but still...

its something I could live with... but it shouldnt be like that and its driving me crazy! :)
Post Reply