How to get file extension

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
silhoutte
Forum Newbie
Posts: 2
Joined: Tue Feb 23, 2010 9:53 pm

How to get file extension

Post by silhoutte »

Hello,

I'd like to know how you can get a file extension from a file stored in a url

===========================
For example:

file (john.txt) is stored in this url http://www.warehouse.com/manager/getperson.php?id=12345

If you click on that link it will give you the text file to download.
===========================

The thing is I'd like to know how can I get the extension out of that file (.txt)

file_put_content -> I can save the file ... but I won't know what's the extension
pathinfo() -> only give me the last 4 character in the link

Help please, thank you very much
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to get file extension

Post by John Cartwright »

You need to parse the headers returned, not the request url..

Hint:

Code: Select all

print_r(get_headers($url, 1));
Post Reply