【问题标题】:How to move uploaded files to public folder inside the public_html in Laravel?如何将上传的文件移动到 Laravel 中 public_html 内的公用文件夹?
【发布时间】:2018-04-27 13:57:15
【问题描述】:

我有一个 laravel 网站正在运行,但我面临文件上传问题。我正在使用移动功能将我上传的文件移动到我的公共文件夹。它在我的 Xampp 中运行良好,但是当我将网站上传到我的服务器时,它不再工作了,因为公共文件夹现在位于 public_html 中。 有什么帮助吗??

【问题讨论】:

  • 你为什么使用move函数? Laravel 有惊人的 file storage functions,你应该使用它。
  • 你能帮我如何指向 public_html 内的公用文件夹吗?

标签: php laravel


【解决方案1】:

要将文件移动到的目的地

 $destinationPath = 'img';

图像新名称

$imageName = 'img_' . rand(1000000, 9999999) . '.' . $request->file('file_name')->getClientOriginalExtension(); //$product->id . '.' .$request->file('file_name')->getClientOriginalExtension();

移动文件

$request->file('file_name')->move($destinationPath, $imageName);

文件路径

$path = public_path() . '/' . $destinationPath . '/' . $imageName;

【讨论】:

  • 我的 laravel 文件夹与 public_html 文件夹处于同一级别。我想将用户上传的文件移动到 public_html/img 文件夹中。
  • 你的 laravel index.php 文件在哪里。它在同一个目录 public_html/index.php 内吗?
猜你喜欢
  • 2021-05-02
  • 2011-10-08
  • 2020-02-18
  • 1970-01-01
  • 2017-11-18
  • 2020-08-01
  • 2019-01-31
  • 2015-07-23
  • 2021-07-23
相关资源
最近更新 更多