Uploading Files: Restricting File Extensions Part 2

+2 Logan R Logan · December 2, 2014
Hello Maiestro!

First i have to say this is a very good tutorial. We can check the type of the file, and if its not JPEG, or jpg it wont be uploaded. This codes says after the dot there is the extension of the file, but what if the file name has more than one dot inside?

For example: 2013-09-04_15.08.41.jpg This file has jpg extension, but you can see there is more than one dots in its name, sot the count will start at the first dot, and the extension will be: 08.41.jpg

Greatings from Hungary!


Post a Reply


Oldest  Newest  Rating
+1 Ricky singh · December 4, 2014
Hello Logan ,

i am glad i could help. 

+1 Ricky singh · December 2, 2014
hello friends.

i hope my short example will help you

$nameOfFile = '2013-09-04_15.08.41.jpg'; // name of the file
$kaboom = explode('.', $nameOfFile); // ecploding the string using '.'
$ext = end($kaboom); // selecting the last file extention.

for rechecking copy and paste the code to check the answer , hopefully you will get jpg as output.

cheers from India.

-1 Logan R Logan · December 3, 2014
Hello Ricky!

Thank you very much for your fast answer!
It helped me out! Yestarday was thinkin' to use somehow the the explode function too, but iam just a beginer in php so i couldn't make it.
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.