Page 1 of 1

Issue with File Download when cancelled

Posted: Fri Nov 11, 2005 9:21 am
by Deltran
I'm having an issue with fopen on my page.
More specifically, if a user cancels a download started with fopen.

I have script after the fread is done that needs to be executed. When a user starts the download but hits cancel the script following never get's called. Is there a way to run code in such an event? Or am I doomed in this reguard?

Code: Select all

//Code to set variables here
       $fileSize = fileSize($path);

		//create the header
		header("Content-Type: $fileType");
		header("Content-Disposition: attachment; filename=$fileName");
		header("Content-Length: ".$fileSize);
		header("Content-Transfer-Encoding: binary");
	
		//send it
		$fo=fopen($path,"rb");
		print fread($fo, $fileSize);
		fclose($fo);
//More code down here
That's what I have. Is there a better way of doing this? Please let me know, espeically if it lets me run code in the case of a close.

Posted: Fri Nov 11, 2005 9:36 am
by feyd

Posted: Fri Nov 11, 2005 9:55 am
by Deltran
That solution works perfectly.
Thanks for the light! Didn't even know that the connection functions even existed. Perhaps its time for me to learn a few more google search tips :(

Have a good one!

Posted: Fri Nov 11, 2005 9:56 am
by Charles256
general note: if your trying something you've never done before and it seems insanely hard, search the manual. that bugger is full of functions I never even thought of. ucwords() was one I enjoyed.heh

Posted: Fri Nov 11, 2005 10:10 am
by Deltran
Wow, you're right.
I should try to read through the list of functions sometime. Maybe their names will linger in my mind and will set off a flag if I'm trying to code something that they can do.

Thanks for the tip!