The bit I don't get about kragoth's suggestion is the first sentence; it seems a bit excessive to write a file on the server's drive and send a URL to it - when you could just send the file data itself with the appropriate headers as per the second sentence there. For one thing, you don't know how long it will be before it's safe to delete (I came across one site with a section that works like that - NASA, as it happens).
I've got a copy of the PHPMyAdmin source handy, but for some reason I'm not inclined to burrow through to see how it does the trick.