Are you locked into a PHP-only solution for some reason??
I only ask because this seems like a great opportunity for JavaScript to show off a little.
I'm sure someone more experienced than myself could come up with other
(and possibly more elegant??) solutions, but my thought is to leave them as simple links on the page you serve.
Then, use JS to override their default behavior and make an AJAX call to a separate PHP script that serves up the file & does whatever other background stuff you might have in mind.
I have some code clips that can
at least get you rolling ... but they're on my dev machine at the shop.
Let me know if there are any constraints you are working under, and I'll
try to remember to check back in tomorrow morning
(cross your fingers & hold your breath
).
At a bare minimum, I hope this at least gives you some additional Google fodder.