Get extension of a file using PHP

1 · Subin Siby · Sept. 4, 2012, 2:59 p.m.
This function will allow you to get a file’s extension in PHP. function getExtension($fileName){ $i = strrpos($fileName, "."); if (!$i) { return ""; } $length = strlen($str) - $i; $extens = substr($str, $i+1, $length); return $extens; } For example you need to get a extension of the file photo.jpg. To get the extension type this code in your PHP file. <span style="color: #660000;"<?php</span <span style="color: #660000;"echo</span getExtension<span style="color: #660000;"...