Scroll to top

How to fetch file name, extension and basename from url in php?

Fetch file name, extension and basename from url in php

<?php
$file = ‘http://localhost/brrrr/wp-content/uploads/2019/11/New-Business-card-4.jpg’;
$ext = pathinfo($file);
echo $ext[‘dirname’] . ‘<br/>’;   // Returns folder/directory
echo $ext[‘basename’] . ‘<br/>’;  // Returns file.html
echo $ext[‘extension’] . ‘<br/>’; // Returns .html
 echo $ext[‘filename’] . ‘<br/>’;  // Returns file
?>

Get more information

Read More Posts

Leave a Reply

Your email address will not be published. Required fields are marked *