Mkdir/fopen problems

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:

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.

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


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

Should be


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

typical mistake xD