fopen("$var/index.php","x") doesn't work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jackount
Forum Newbie
Posts: 13
Joined: Wed Aug 10, 2011 5:38 am

fopen("$var/index.php","x") doesn't work

Post by Jackount »

Code: Select all

		$file = fopen("./$l/index.php",'x');
I'm calling the above function, wanting to create a file, that does not exist already. It worked before I made the $l be a folder, when $l was the filename ( fopen("$l.php",'x'); )

Code: Select all

		$file = fopen("./".$l."/index.php",'x');
^^ Doesn't work either...
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: fopen("$var/index.php","x") doesn't work

Post by Celauran »

Try using is_dir() to see if the directory exists, then create it if necessary.
Jackount
Forum Newbie
Posts: 13
Joined: Wed Aug 10, 2011 5:38 am

Re: fopen("$var/index.php","x") doesn't work

Post by Jackount »

Well, I KNOW the directory doesn't exist? I just want to create the file in that given foldername... should be possible ;o
martelo59
Forum Newbie
Posts: 6
Joined: Sat Oct 22, 2011 3:55 am

Re: fopen("$var/index.php","x") doesn't work

Post by martelo59 »

I'm calling the above function, wanting to create a file, that does not exist already.
Whay you dont use fwrite and make "w+" for writing, that function will make your file. If you don't have created directory first use mkdir, after this fwrite.
Post Reply