【问题标题】:Iterate through multiple request files with Laravel 4使用 Laravel 4 遍历多个请求文件
【发布时间】:2023-03-19 10:05:01
【问题描述】:

有没有办法遍历 Laravel 4 中的请求文件对象? 我想做这样的事情:

foreach (Input::files() as $file) {
  $filename = str_random(8) . '-' . $file->getClientOriginalName();
  $uploadSuccess = $file->move($destinationPath, $filename);
  // ...
}

我想使用 Input:: 方法而不是迭代 $_FILES 数组。 谢谢

【问题讨论】:

标签: php laravel laravel-4


【解决方案1】:

进入 Symfony 代码,您可能能够:

foreach (Request::instance()->files->all() as $file) {
  $filename = str_random(8) . '-' . $file->getClientOriginalName();
  $uploadSuccess = $file->move($destinationPath, $filename);
  // ...
}

看看

Symfony\Component\HttpFoundation\FileBag

Symfony\Component\HttpFoundation\ParameterBag

为了更好地了解您可以使用它们做什么。

【讨论】:

  • Strangle $file 是我的文件数组
猜你喜欢
  • 2017-07-05
  • 1970-01-01
  • 1970-01-01
  • 2020-11-16
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 2018-10-25
  • 2019-07-21
相关资源
最近更新 更多