存储在Laravel中的File::put()在哪里


Where is the File::put() stored in Laravel?

我有一个关于Laravel的问题,File::put()存储在Laravel中的哪里?

我已经检查了storage/app/public内部,但内容不在那里。

要将文件存储在文件夹storage/app中,必须将Storage类用作:

Storage::disk('local')->put('file.txt', 'Contents');

则它将在CCD_ 5中存储一个文件。

单据

File::put存储在public文件夹中

例如。在这种情况下,file.txt将在公用文件夹中创建

File::put('file.txt', 'contents is written inside file.txt');

您也可以使用存储类

Storage::put( 'file.txt','contents is written inside file.txt' );

这将在storage'app 中创建文件

以确保您可以使用功能定位

  • public_path((
  • 存储路径((
  • app_path((

例如:

File::put(public_path('uploads'), $data);

另一种方法可以做到这一点,您可以指定文件的file_namepath。将使用storeAs

所以你最终会得到这样的

$file = $request->file('file');    
// Generate a file name with extension
$fileName = 'profile-'.time().'.'.$file->getClientOriginalExtension();
// Save the file
$path = $file->storeAs('files', $fileName);
dd($path);

#输出

"files/profile-15564586486.jpg";