# \[php\] if elses help

**URL:** <https://forum.kirupa.com/t/php-if-elses-help/65034>\
**Category:** programming\
**Created:** [September 22, 2004, 12:01pm UTC](https://forum.kirupa.com/t/php-if-elses-help/65034 "2004-09-22T12:01:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alapimba](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@alapimba](https://forum.kirupa.com/u/alapimba)\
**Post date:** [September 22, 2004, 12:01pm UTC](https://forum.kirupa.com/t/php-if-elses-help/65034/1 "2004-09-22T12:01:01Z")

</div>

hello  
my question is pretty simple.  
i have and upload form with this to check the file format:

$types\_array = array(“image/gif”,“image/pjpeg”,“image/x-png”);  
if (!in\_array($\_FILES[‘userfile’][‘type’], $types\_array)) {  
echo "file type not allowed  
";  
exit;  
}

and then i have this:  
if ($\_FILES[‘userfile’][‘name’] == “”) {  
$dir = $\_POST[‘fotohidden’];  
} else {  
$dir = $uploadfile;  
}

how can i put that file check thing inside my else… i mean… i only want it to check the file type when the file name is not empty…

i guess the code is all there it’s just a question of if’s and elses and i don’t know how to write them 😊

Thanks once again

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 22, 2004, 7:02pm UTC](https://forum.kirupa.com/t/php-if-elses-help/65034/2 "2004-09-22T19:02:29Z")

</div>

> [@alapimba](#):
>
> how can i put that file check thing inside my else… i mean… i only want it to check the file type when the file name is not empty…
> 
> i guess the code is all there it’s just a question of if’s and elses and i don’t know how to write them 😊

```php

$types_array = array("image/gif","image/pjpeg","image/x-png");

if ($_FILES['userfile']['name'] == "") {
  $dir = $_POST['fotohidden'];
} else {
  if (!in_array($_FILES['userfile']['type'], $types_array)) {
    echo "file type not allowed
";
    exit;
  }
  $dir = $uploadfile;
}

```

Hope that helps.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2004, 5:04pm UTC](https://forum.kirupa.com/t/php-if-elses-help/65034/3 "2004-09-23T17:04:37Z")

</div>

thx 😉
