Home » PHP Code »

2

This post explains about how to get file extenstion using the php. In the we have two types to retrieve the file extensions. See the  following script :

Type 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
function findextension ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$filename="image.jpg";
echo findextension ($filename);
// Here we will get the file extension

$filename="image.jpg";

echo findextension ($filename);

// Here we will get the file extenstion

?>

Type 2:

Another way to get file extension:

1
2
3
4
5
6
7
8
9
<?php

function file_extension($filename)
{
return end(explode(".", $filename));
}

echo file_extension("anil.labs.jpg");
?>

Thanks,
Anil Kumar Panigrahi


Related Posts

    We get the address by latitude and longitude -using php codeHow to add HTML content in php mail() functionGoogle maps using php codeHow to remove consecutive whitespaces using php?

 

2 Comments

  1. Can u help me.

    how to redirect URL’s using .htaccess file

    like this

    http://domain.com/index.php?id=srinivas&page=2

    to

    http://domain.com/srinivas?page=2

Leave a Reply