napalm Posted July 1, 2010 Share Posted July 1, 2010 is there any way to create/write not just one file but multiple in one fwrite? so writing one file is like this yah? $dir='dir/'; $myFile = ''.$dir.'file.txt'; $fh = fopen($myFile, 'x+') or die("can't open file"); $content = "content blah blah"; fwrite($fh, $content); theres no way to possibly like separating in the fopen to multiple files with a ,? $dir='dir/'; $myFile = ''.$dir.'file.txt'; $myFile2 = ''.$dir.'file2.txt'; $fh = fopen($myFile,$myFile2 'x+') or die("can't open file"); $content = "content blah blah"; fwrite($fh, $content); or with ||? $dir='dir/'; $myFile = ''.$dir.'file.txt'; $myFile2 = ''.$dir.'file2.txt'; $fh = fopen($myFile || $myFile2 'x+') or die("can't open file"); $content = "content blah blah"; fwrite($fh, $content); any ideas? thanks Quote Link to comment Share on other sites More sharing options...
Mchl Posted July 1, 2010 Share Posted July 1, 2010 No there is not. One handle - one file. Quote Link to comment Share on other sites More sharing options...
napalm Posted July 1, 2010 Author Share Posted July 1, 2010 damn, so is there any other way other then fwrite,fopen possibly to create multiple files? Quote Link to comment Share on other sites More sharing options...
rwwd Posted July 1, 2010 Share Posted July 1, 2010 [Gah, Mchl beat me to it!] Firstly:- $myFile = ''.$dir.'file.txt'; can be done:- $myFile = $dir."file.txt"; and fopen(FILE.txt, "r");//whatever mode you want only takes one parameter/filename at a time, multiple opens needs multiple calls to fopen, at least thats my understanding of it, I usually put a ternary somewhere & check to see if one exist && if not open the other, kinda like a failsafe if you see what I mean Rw Quote Link to comment Share on other sites More sharing options...
Mchl Posted July 1, 2010 Share Posted July 1, 2010 What's wrong with opening two handles? <?php $dir='dir/'; $myFile1 = $dir.'file.txt'; $myFile2 = $dir.'file2.txt'; $fh1 = fopen($myFile1,'x+') or die("can't open file $myFile1"); $fh2 = fopen($myFile2,'x+') or die("can't open file $myFile2"); $content = "content blah blah"; fwrite($fh1, $content); fwrite($fh2, $content); Quote Link to comment Share on other sites More sharing options...
napalm Posted July 1, 2010 Author Share Posted July 1, 2010 yeah im going to end up having to do that but its going to go to multiple directories just wanted to see if there was a simple way of just serperating them. Quote Link to comment Share on other sites More sharing options...
napalm Posted July 1, 2010 Author Share Posted July 1, 2010 Sorry for the double post but i got this figured out! what i did is i opened the directory and listed each directory and just added the fwrite an what not where the list goes like this: <?php $dirname = "dir/"; $dirread = opendir($dirname); while(false != ($file = readdir($dirread))) { if(($file != ".") and ($file != "..")) { $dir='dir/'.$file.''; $myFile = ''.$dir.'.txt'; $fh = fopen($myFile, 'x+') or die("can't open file"); $content = "content blah blah"; fwrite($fh, $content); fclose($fh); }} ?> an it worked this way! Just for any one wondering Thanks guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.