conan's avatar
Level 1

How to get a file line by line in the Laravel Storage path file???

There's a uploaded text file in the Laravel's storage path. "abc.csv" I'd like to read the "abc.csv" file line by line. and extract it by line into another file..

for example, extract every 2 line( 0, 2 4, 6, 8, ... lines) into "a2.csv",,,

extract every 3 lines(0,3,6,9,12... lines) into "a3.csv",

extract every 5 lines(0,5,10,15,20.. lines) into "a5.csv"

should I use the traditional php file read function, such as fopen()...?

while(..all lines){ read line by line; if(line counter % 2==0) write "a2.csv" file else if(line counter %3 == 0) wirte "a3.csv" file...

and so on..

Is there laravel storage File System api relating this to read line by line ?

0 likes
1 reply
MichalOravec's avatar

Instead of fopen you can use

$contents = Storage::get('path-to-your/abc.csv');

Please or to participate in this conversation.