yhi Posted October 24, 2017 Share Posted October 24, 2017 i want my php script to read a local file ~56mb (1000+ lines) and perform a operation on each of the lines separately i am not sure how to do this i have no clue how to properly read file can i use file_get _contents( ) ? and after reading how to perform the operation on each lines separately can i use forreach ? PS it it makes ant difference those 1000+ lines are base64encoded lines and i want to decrypt them each line seprately Quote Link to comment https://forums.phpfreaks.com/topic/305443-reading-and-performing-action/ Share on other sites More sharing options...
Sepodati Posted October 24, 2017 Share Posted October 24, 2017 http://php.net/manual/en/function.file.php Quote Link to comment https://forums.phpfreaks.com/topic/305443-reading-and-performing-action/#findComment-1553001 Share on other sites More sharing options...
yhi Posted October 24, 2017 Author Share Posted October 24, 2017 <?php $handle = fopen("data.txt", "r"); if ($handle) { while (($line = fgets($handle)) !== false) { $current=base64_decode($line); $file=rand(); file_put_contents($file, $current); echo"done"; } fclose($handle); } else { echo"error opening the file."; } ?> i wrote this script but in my output file i only got 2.97kb data data.txt have 8kb data in each line Quote Link to comment https://forums.phpfreaks.com/topic/305443-reading-and-performing-action/#findComment-1553002 Share on other sites More sharing options...
kicken Posted October 24, 2017 Share Posted October 24, 2017 file_put_contents replaces the content of a file by default. You can pass the FILE_APPEND flag in the third parameter to have it append to the file instead. Quote Link to comment https://forums.phpfreaks.com/topic/305443-reading-and-performing-action/#findComment-1553003 Share on other sites More sharing options...
yhi Posted October 25, 2017 Author Share Posted October 25, 2017 file_put_contents replaces the content of a file by default. You can pass the FILE_APPEND flag in the third parameter to have it append to the file instead. file_put_contents replaces the content of a file by default. You can pass the FILE_APPEND flag in the third parameter to have it append to the file instead. ok but what about the size limit ? each line is 8kb but i am only receiving 2.97ks in output what could be the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/305443-reading-and-performing-action/#findComment-1553014 Share on other sites More sharing options...
yhi Posted October 25, 2017 Author Share Posted October 25, 2017 it seems line base64_decode(); is the one causing problem i tried a few sites to decrypt the 8kb string manually i only received a partial output how to fix it ? Quote Link to comment https://forums.phpfreaks.com/topic/305443-reading-and-performing-action/#findComment-1553016 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.