当我使用
$request->file('files')
[2018-11-12 16:10:03] local.DEBUG: array (
0 =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'test-pdf.pdf',
'mimeType' => 'application/pdf',
'error' => 0,
'hashName' => NULL,
)),
1 =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'test-pdf.pdf',
'mimeType' => 'application/pdf',
'error' => 0,
'hashName' => NULL,
)),
2 =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'test-pdf.pdf',
'mimeType' => 'application/pdf',
'error' => 0,
'hashName' => NULL,
)),
)
我想访问数组中的每个文件并获得如下路径名:
$files = $request->files;
foreach ($files as $key => $file) {
Log::debug($file->getPathName());
}
但是,这会引发以下错误:
local.ERROR: Call to a member function getPathName() on array {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function getPathName() on array at /home/vagrant/Projects/business-risk-portal/app/Http/Controllers/FileController.php:68)
更新
$files = $request->files;
foreach ($files as $key => $file) {
$temp_path = $request->file('tmp.' . $key);
Log::debug($temp_path->getPathName());
}
我得到:
Call to a member function getPathName() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function getPathName() on null at /home/vagrant/Projects/business-risk-portal/app/Http/Controllers/FileController.php:69)