Get file name from URL

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
krethan
Forum Newbie
Posts: 3
Joined: Tue Mar 29, 2011 12:59 am

Get file name from URL

Post by krethan »

Sometimes the location: is not given as part of the HTML response header.
Does anyone know how to determine the filename without this key piece of information?

Example http://www.somewebsite.com
If you find a location: in the HTML response header you know the filename. Location: index.html

Any ideas?
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: Get file name from URL

Post by Peter Kelly »

Might help if you look into the function parse_url http://uk.php.net/manual/en/function.parse-url.php
krethan
Forum Newbie
Posts: 3
Joined: Tue Mar 29, 2011 12:59 am

Re: Get file name from URL

Post by krethan »

I already checked out that function. It breaks up the url into path and filename but the filename has to be part of the url.
izapharry
Forum Newbie
Posts: 8
Joined: Mon Jul 20, 2009 7:00 am

Re: Get file name from URL

Post by izapharry »

if your site open with index.php then you should use conical tag for the redirection.
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: Get file name from URL

Post by Peter Kelly »

Yeah but if it breaks it up then you can piece it back together

Code: Select all

$url = parse_url(http://username:password@hostname/path?arg=value#anchor'));

echo $url['scheme'] . ":" . $url['host'] .$url[path'];
Surely that would work for what you need?
Post Reply