jamesxg1 Posted July 15, 2009 Share Posted July 15, 2009 Hiya, Basically i am trying to make a code that will find every .php formatted file in the directory and login it in a .txt formatted file like so, FILENAME.php - FILESIZE Here is the code i made so far, <?php $a_str = glob("*.php"); foreach ($a_str as $filename); $size = filesize($filename); $contents = implode(PHP_EOL, $a_str); $contents = "$filename - $size"; $contents .= PHP_EOL . PHP_EOL; file_put_contents("datafiles.txt", $contents); print("$contents"); ?> It works except for the slight fact that it is only putting one line !, this is copyed from the text file, "write.php - 289" and it wont do them all line after line how do i fix this ?, Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/166090-solved-php-filesystem-help-glob-ect/ Share on other sites More sharing options...
rhodesa Posted July 15, 2009 Share Posted July 15, 2009 you need braces around your foreach statement. I also shortened it up a little: <?php $contents = ""; foreach(glob("*.php") as $filename){ $contents .= $filename . " - " . filesize($filename) . PHP_EOL . PHP_EOL; } file_put_contents("datafiles.txt", $contents); print $contents; ?> Link to comment https://forums.phpfreaks.com/topic/166090-solved-php-filesystem-help-glob-ect/#findComment-875914 Share on other sites More sharing options...
jamesxg1 Posted July 15, 2009 Author Share Posted July 15, 2009 Sorry for the extra post, this works on screen (print"") but dont put it in the .txt file. <?php $a_str = glob("*.php"); foreach ($a_str as $filename) { $size = filesize($filename); $contents = "$filename - $size"; file_put_contents("datafiles.txt", $contents); print("$contents<br>"); } ?> Link to comment https://forums.phpfreaks.com/topic/166090-solved-php-filesystem-help-glob-ect/#findComment-875916 Share on other sites More sharing options...
jamesxg1 Posted July 15, 2009 Author Share Posted July 15, 2009 you need braces around your foreach statement. I also shortened it up a little: <?php $contents = ""; foreach(glob("*.php") as $filename){ $contents .= $filename . " - " . filesize($filename) . PHP_EOL . PHP_EOL; } file_put_contents("datafiles.txt", $contents); print $contents; ?> Lol just seen the same lol, but that's a lot shorter cheers mate thanks for your help, rhodesa is a ' * ' . Link to comment https://forums.phpfreaks.com/topic/166090-solved-php-filesystem-help-glob-ect/#findComment-875918 Share on other sites More sharing options...
rhodesa Posted July 15, 2009 Share Posted July 15, 2009 np Link to comment https://forums.phpfreaks.com/topic/166090-solved-php-filesystem-help-glob-ect/#findComment-875924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.