reenadak icon

Get File Extension

reenadak | PRO | 02/20/18 06:42:35 PM UTC | 0 ⭐ | 422 👁️ | Never ⏰ | []
PHP |

510 B

|

None

|

0 👍

/

0 👎

    /*
    - Get File Extension
    - Gets the file extension from the file's name.
    
    $fileName      - The name of the file to get the extension of.
    $includePeriod - Whether or not to include the prefix period (eg. ".txt")
    */
    
    public function getFileExtension($fileName, $includePeriod = true) {
        if (strpos($fileName, ".")) {
            $sides = explode(".", $fileName);
            $ext = "";
 
            if ($includePeriod)
                $ext .= ".";
 
            $ext .= $sides[count($sides) - 1];
            return $ext;
        } else
            return "N/A";
    }

Comments