Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a text file and a JSON with laravel 4 framework?

Hello!, the question might be simple, but i couldn't find the answer.

i want to create a .txt file with laravel 4 and upload it to my server like PHP does, and also i need to create a JSON file with laravel 4 and upload it to my server.

Thanks for your help!

like image 310
Rodrigo Calix Avatar asked Nov 19 '14 05:11

Rodrigo Calix


1 Answers

To use the filesystem of Laravel, you should access it through the File Facade.

Create a new file:

//Usage
File::put($path,$contents);
//Example
File::put('web/text/mytextdocument.txt','John Doe');

Delete a file:

//Usage
File::delete(string|array $paths)
//Example
File::delete('web/text/mytextdocument.txt');

The complete documentation on all available methods is found here: https://laravel.com/api/4.2/Illuminate/Filesystem/Filesystem.html

like image 156
Mysteryos Avatar answered Oct 07 '22 00:10

Mysteryos