# Mkdir/fopen problems

**URL:** https://forum.kirupa.com/t/mkdir-fopen-problems/259927
**Category:** Uncategorized
**Created:** [May 10, 2008, 10:08am UTC](https://forum.kirupa.com/t/mkdir-fopen-problems/259927 "2008-05-10T10:08:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![FreakSheep](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@FreakSheep](https://forum.kirupa.com/u/FreakSheep)
#### Post date: [May 10, 2008, 10:08am UTC](https://forum.kirupa.com/t/mkdir-fopen-problems/259927/1 "2008-05-10T10:08:47Z")

</div>

Hey guys,

I’m running apache on my macbook here, so i’m not completely sure if it’s a platform problem.

I need to make x number of directories with an index.php in each.

code so far:

```php
if(is_dir("../a/$parent")){
                        echo "Exists";
                        $mkfile=false;
                    }else{
                        echo "Does not exist";
                        echo "<br />Making Directory... ";
                        if(mkdir("../a/$parent",0777)){
                            echo "Done.";
                            $mkfile=true;
                        }else{
                            echo "Error: Directory cannot be created.";
                            $go=false;
                            $mkfile=false;
                        }
                    }
                    
                    if($mkfile){
                        $data="This is text for my new file :)";
                        $f=fopen('../a/$parent/index.php','w') or die('nogo');
                        if($f=false){
                            echo "<br />Error: Cannot make index file.";
                            $go=false;
                        }
                        if(fwrite($f,$data)==false){
                            echo "<br />Error: Cannot make index file.";
                            $go=false;
                        }
                        fclose($f);
                    }

```

The directory is made, but the ‘nogo’ error pops up.

any idea?

naaman.

---

<div class="post-metadata">

### Author: ![Yeldarb](https://avatars.discourse-cdn.com/v4/letter/y/51bf81/32.png) [@Yeldarb](https://forum.kirupa.com/u/Yeldarb)
#### Post date: [May 10, 2008, 4:36pm UTC](https://forum.kirupa.com/t/mkdir-fopen-problems/259927/2 "2008-05-10T16:36:58Z")

</div>

You’re assigning false to $f rather than comparing it.

```php

if($f=false){
	echo "<br />Error: Cannot make index file.";
	$go=false;
}

```

Should be

```php

if($f==false){
	echo "<br />Error: Cannot make index file.";
	$go=false;
}

```

---

<div class="post-metadata">

### Author: ![Loyx](https://avatars.discourse-cdn.com/v4/letter/l/e274bd/32.png) [@Loyx](https://forum.kirupa.com/u/Loyx)
#### Post date: [May 10, 2008, 10:31pm UTC](https://forum.kirupa.com/t/mkdir-fopen-problems/259927/3 "2008-05-10T22:31:55Z")

</div>

typical mistake xD
