# Check if file is JPG

**URL:** https://forum.kirupa.com/t/check-if-file-is-jpg/295344
**Category:** programming
**Created:** [August 28, 2009, 1:23pm UTC](https://forum.kirupa.com/t/check-if-file-is-jpg/295344 "2009-08-28T13:23:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ruiganga](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ruiganga/32/3679_2.png) [@ruiganga](https://forum.kirupa.com/u/ruiganga)
#### Post date: [August 28, 2009, 1:23pm UTC](https://forum.kirupa.com/t/check-if-file-is-jpg/295344/1 "2009-08-28T13:23:18Z")

</div>

Hi

I am creating a simple script that uses scandir() to generate a XML with the images list inside a folder. My doce is:

```php
$dir = "images/"; //You could add a $_GET to change the directory 
$files = scandir($dir); 
echo "<?xml version='1.0'?>";
echo "<list>";
foreach($files as $key => $value){ 
echo "<image>".$value."</image>"; //You could add an icon in here maybe, a link to the file/directory, or a link to list files in that directory 
echo "</list>";
} 
?>

```

The only problem, or lets call bug, I found in this script is that if I have some other file with another extension the script will list it too.

What I need is a way to check if the value is a jpg. Can anyone give me a hint?

Thanks
