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 Link to comment 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 Link to comment 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 Link to comment 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. Link to comment 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 ? Link to comment 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 ? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.