Wednesday, June 17, 2015

PHP basename() Function

The basename() function return file name from the path. This Function Mostly used when we want the only filename from web URL.

Syntax of Basename() function

The basename() function takes two Parameters. In first $path parameter Pass file URL or directory where the file is located and second $suffix parameter pass file format like (.jpg,.png.pdf), etc. Whenever the file format match this will be cut off.
<?php basename ($path ,$suffix ); ?>

Example of Basename() Function

Below code will upload an image from any path or directory to your define folder.
<?php
$path = "http://www.bestphptuts.blogspot.com/logo.png";
$name = basename($path);
$folder = "your_folder_name";
file_put_contents("$folder/$name", file_get_contents($path));
?>

0 comments:

Post a Comment