sairam93's avatar

Text file Upload and get the content

I have used Storage storeas method to save text file in storage/app/ folder. I want to get the contains. when I used the storage::get method, it is returning all the contain as a string. I actually want each line as one value in array.

something like fgets() where I get the each line and store it as each value in an array

0 likes
3 replies
jlrdw's avatar

Just use fgets() and in the while loop put the contents into your array.

sairam93's avatar

I have isssues giving the path for fgets. My text files are in storage/app/Newfolder/file.txt

Any help please?

jlrdw's avatar
jlrdw
Best Answer
Level 75

Have you tried the storage_path() helper, otherwise

My main laravel is called laravel54up above htdocs

In index.php (which is under htdocs) you see a line like

require __DIR__.'/../../laravel54up/bootstrap/autoload.php';

above that line somewhere put

defined('DS') || define('DS', DIRECTORY_SEPARATOR);
define('ROOTDIR', realpath(__DIR__ .'/../../laravel54up') .DS);
define('MYTEXT', ROOTDIR . 'storage' . DS . 'app' . DS . 'yourfolder' . DS);

Now you have a constant to use.

Of course name how you need, and resolve your paths to your system, don't literally put what I have.

If you are new to this stuff, you may need some more learning in php basics, how to resolve paths, etc.

Believe me, if you had months or years of basic php usage this stuff would be much easier for you.

Please or to participate in this conversation.