Magento Expert Forum - Improve your Magento experience

Results 1 to 3 of 3

Easy way to get file extension in PHP

  1. #1
    Moderator speed2x's Avatar
    Join Date
    Mar 2013
    Location
    Hollywood, Florida, United States
    Posts
    88
    Thanks
    8
    Thanked 7 Times in 6 Posts

    Post Easy way to get file extension in PHP

    I use this code many times in my projects and now I share you this useful code. Sometimes in coding a very simple task can take you a lot of time to make a perfect solution. To get a file extension sometimes take me 30 mins to do the perfect code what work well in all of situation. But now it should take one minute with this code:

    PHP Code:
    function get_file_extension($file_name) {
        return 
    substr(strrchr($file_name,'.'),1);

    This simple method of file extension retrieval should be reused throughout your code.

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Sep 2018
    Location
    Oman, Muscat
    Posts
    2,084
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    if $file has no extension, you get wrong variable values: $extension would be assigned with Simple example of pathinfo and array destructuring in PHP 7:

Similar Threads

  1. SEO in Ten Easy Steps
    By ccvv in forum Magento SEO technique
    Replies: 22
    Last Post: 28-11-2019, 02:08 PM
  2. Replies: 1
    Last Post: 14-03-2019, 07:22 AM
  3. Easy and Affordable Magento Hosting
    By sgdev in forum Magento Hosting, VPS, Server by Siteground
    Replies: 15
    Last Post: 15-09-2018, 08:28 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •