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 Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/ 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. Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/#findComment-1079957 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? Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/#findComment-1079958 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 Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/#findComment-1079960 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); Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/#findComment-1079963 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. Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/#findComment-1079966 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! Link to comment https://forums.phpfreaks.com/topic/206448-multiple-files-in-fwrite/#findComment-1079975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.