How to get a file’s extension in PHP?

Spread the love

Sometimes, we want to get a file’s extension in PHP.

In this article, we’ll look at how to get a file’s extension in PHP.

How to get a file’s extension in PHP?

To get a file’s extension in PHP, we call the pathinfo function.

For instance, we write

$ext = pathinfo($filename, PATHINFO_EXTENSION);

to call pathinfo with $filename and PATHINFO_EXTENSION to return the file extension part of the $filename path string.

Conclusion

To get a file’s extension in PHP, we call the pathinfo function.

Leave a Reply

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