Page 1 of 1

Get file name from URL

Posted: Tue Mar 29, 2011 1:04 am
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?

Re: Get file name from URL

Posted: Tue Mar 29, 2011 6:20 am
by Peter Kelly
Might help if you look into the function parse_url http://uk.php.net/manual/en/function.parse-url.php

Re: Get file name from URL

Posted: Tue Mar 29, 2011 10:19 pm
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.

Re: Get file name from URL

Posted: Wed Mar 30, 2011 12:22 am
by izapharry
if your site open with index.php then you should use conical tag for the redirection.

Re: Get file name from URL

Posted: Wed Mar 30, 2011 1:32 am
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?