04 January 2020

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 
?>

No comments:

Post a Comment

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...