Reputation: 411
I wanted to get the file extension of online file but problem is that some files are not having extension in their url. For Example http://www.example.com/page?=10
Upvotes: 0
Views: 787
Reputation: 392931
Just get the file, and read the content-disposition's filename
You'll a header something like
Content-Disposition: attachment; filename=FILENAME
You can then establish the extension from FILENAME
Upvotes: 1
Reputation: 1062770
The first to to look for is a "content-disposition" header; if that exists, and in particular if it starts "attachment", then it represents an explicit download, and the "content-disposition" header may (optionally) contain the preferred filename, which may include an extension.
If that doesn't help, then look at the "content-type" header; you may have to infer a few things for common types.
But to state it explicitly: file extensions don't rule on the internet.
Upvotes: 3
Reputation: 91825
URLs don't necessarily relate to files. If the URL has no extension, then the "file" has no extension. Or were you trying to infer the extension from the content type?
Upvotes: 1