开发者

How to get file extension of online file having no extension in url

I wanted to get the file extension of online file but problem is that some files are not having ex开发者_开发问答tension in their url. For Example http://www.example.com/page?=10


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.


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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜