Reputation: 113
I need to download files from remote server with my PHP script. The problem is that the links I recieve look like "example.com?download=12345". So I want to save the file with correct extension and (at best) preserve it's original filename. How do I do this? Thank you all!
Upvotes: 2
Views: 2487
Reputation: 92762
@EricLaw (of the IE Team) has posted a detailed analysis of this on the IEBlog last November. While his post is focused on IE, the basics hold for most browsers:
However, the source server is not obliged to do any of this; the most likely option would be the Content-Disposition
header. If that is not present, you are back to square 1 (although you could guesstimate the file type from its content).
Upvotes: 0
Reputation: 37065
If you are using curl, the response header should return the actual filename. The header for file downloads looks like:
'Content-Disposition: attachment; filename="downloaded.pdf"'
Upvotes: 0
Reputation: 798716
The Content-Disposition
header in the HTTP response, if it exists, will contain the filename the other server wants the file to have.
Upvotes: 8