Issue with File Download when cancelled

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
User avatar
Deltran
Forum Newbie
Posts: 3
Joined: Fri Nov 11, 2005 9:14 am
Location: Western PA, USA

Issue with File Download when cancelled

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Deltran
Forum Newbie
Posts: 3
Joined: Fri Nov 11, 2005 9:14 am
Location: Western PA, USA

Post 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!
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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
User avatar
Deltran
Forum Newbie
Posts: 3
Joined: Fri Nov 11, 2005 9:14 am
Location: Western PA, USA

Post 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!
Post Reply