We often need to get the file extension of any file while working with php. We can get it in different ways. Here are some functions to get the file extension. Just pass the filename
All above will give us file extension.
$file='myimage.jpg';
(1) echo $ext1= end(explode('.',$file));
(2) echo $ext2= array_pop(explode('.',$file));
(3) echo $ext3= substr(strrchr($file,'.'),1);
(4) $ext4=pathinfo($file);
echo $ext4['extension'];
All above will give us file extension.
Posting Komentar