A simple yet powerful approach to get file extension using PHP. We usually need to extract file extension from file name while uploading file so that we could generate new name and rename file to our convenience. We could create new file name using time, random or hashing, example of which has been given at the last paragraph of this post.
function get_file_extension($filename) {
return substr($filename, strrpos($filename, '.')+1, strlen($filename)-strrpos('.', $filename));
}
Explanation:
It uses built-in substring, strrpos and strlen functions to extract file extension. A brief on these functions. Continue reading


Recent Comments
Arvind Thakur on Simple image rotater with fadeIn fadeOut effect using jQuery
Found even more-more precised and simplest method at Jonathan Snook's blog with a demo. I am sure nothing can be...anil kiumar on Resume download of PART extension file in Firefox
yah bepsait acchi haiArvind Thakur on Simple captcha component for CakePHP 1.x
CakePHP 2.x version of this component is hereArvind Thakur on Resume download of PART extension file in Firefox
As i did not had access to website i tried to reply you last night through email address you posted...sophia on Resume download of PART extension file in Firefox
Hi, I have only part file and I made a copy of it by removing .part. later I moved it to another...