JREAM Posted January 2, 2009 Share Posted January 2, 2009 This keeps replacing itself and there are supposed to be a long list of items <?php function list_mp3s () { $directory = 'public/mp3s/'; $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { // $filename = RemoveExtension($file); // Use this later $fp = fopen('data.txt', 'w'); $data = "<track>"; $data .= "<location>$directory$file</location>"; $data .= "<image></image>"; $data .= "<annotation>$filename</annotation>"; $data .= "</track>"; fwrite($fp, $data); fclose($fp); } }closedir($handler);} // do it list_mp3s(); ?> I can only get it to write one file, Can anyone help me put it into an array and write it at the end if thats how i do it? Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 $fp = fopen('data.txt', 'a'); Quote Link to comment Share on other sites More sharing options...
flyhoney Posted January 2, 2009 Share Posted January 2, 2009 Mchl has the answer. The 'a' flag means to append data to the end of the file instead of overwriting it. Quote Link to comment Share on other sites More sharing options...
JREAM Posted January 2, 2009 Author Share Posted January 2, 2009 The 'a' works, but if i refresh the page, it adds it again, when i got: file1.mp3, file2.mp3, and file3.mp3 if i hit refresh ti will do: file1.mp3, file2.mp3, and file3.mp3, file1.mp3, file2.mp3, and file3.mp3 should I do this before i open: // this would have to go outside of the while loop $fp = fopen('data.txt', 'w'); $data = ""; fwrite($fp, $data); fclose($fp); // then the normal part here: while .... $fp = fopen('data.txt', 'a'); $data = "<track>"; $data .= "<location>$directory$file</location>"; $data .= "<image></image>"; $data .= "<annotation>$filename</annotation>"; $data .= "</track>"; fwrite($fp, $data); fclose($fp); Quote Link to comment Share on other sites More sharing options...
flyhoney Posted January 2, 2009 Share Posted January 2, 2009 <?php function list_mp3s () { $directory = 'public/mp3s/'; $results = array(); $handler = opendir($directory); $data = ''; $fp = fopen('data.txt', 'w'); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $data .= "<track>"; $data .= "<location>$directory$file</location>"; $data .= "<image></image>"; $data .= "<annotation>$filename</annotation>"; $data .= "</track>"; } } fwrite($fp, $data); fclose($fp); closedir($handler); } // do it list_mp3s(); ?> Quote Link to comment Share on other sites More sharing options...
JREAM Posted January 2, 2009 Author Share Posted January 2, 2009 gosh Im such an idiot. thanks fly and mch 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.