php 如何使用 Laravel 4 框架创建文本文件和 JSON?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27009483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:08:13  来源:igfitidea点击:

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

phpjsonfilelaravelframeworks

提问by Rodrigo Calix

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

您好!,问题可能很简单,但我找不到答案。

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

我想用laravel 4创建一个.txt 文件并像 PHP 一样将它上传到我的服务器,我还需要用laravel 4创建一个JSON 文件并将其上传到我的服务器。

Thanks for your help!

谢谢你的帮助!

回答by Mysteryos

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

要使用 Laravel 的文件系统,您应该通过FileFacade访问它。

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

有关所有可用方法的完整文档可在此处找到:https: //laravel.com/api/4.2/Illuminate/Filesystem/Filesystem.html