|
|
PHP
Tutorial
7.To
find the filename ( with extension ) of a file from the absolute or
relative URL
|
|
The basename() function takes the
absolute or relative url and finds the filename with extension.
This function looks for the last (forward slash) /
and returns anything after it as the filename. Trying to
find the basename of a string without even a single / would
return the same string. Using the same function, the name
of a folder or a directory can be found
|
<?php
$url=$_POST['url'];
$filename=basename($url);
?>
<html>
<form name="frm" method="post">
Enter the URL (absolute or relative) : <input
type="text" name="url" size=25>
<br>
<input type="submit" name="submit">
<?php
if($_POST)
{
echo
"The FileName specified in the URL is $filename<br>";
}
?>
</form>
</html>
Go
To Index
|
|
|