我上传表单,我可以上传任何类型的文件并保存到数据库的路径。如果不在数据库中保存任何相关信息,例如:filetype
,filesize
等,我可以在循环结果并在页面上显示这些信息时获取此信息吗?
这是我到目前为止所尝试的内容
public function fileUpload()
{
$allFiles = Documents::paginate(20);
$files = array();
foreach ($allFiles as $file) {
$files[] = $this->fileInfo(pathinfo(public_path() . '/uploads/' . $file));
}
return View::make('admin.files', [
'files' => $files
]);
}
public function fileInfo($filePath)
{
$file = array();
$file['name'] = $filePath['filename'];
$file['extension'] = $filePath['extension'];
$file['size'] = filesize($filePath['dirname'] . '/' . $filePath['basename']);
return $file;
}
运行页面时出现的错误是
ErrorException:filesize():stat for .....
这是正确的做法吗?
更新:dd($filePath['dirname'] . '/' . $filePath['basename']);
返回
string(126) "/var/www/html/site/public/uploads/{"id":2,"document_path":"aut6MnADFrPZTz4TJf0Y.pdf","document_name":"Some title for the file"}"
答案 0 :(得分:0)
更改此行
$files[] = $this->fileInfo(pathinfo(public_path() . '/uploads/' . $file));
到
$files[] = $this->fileInfo(pathinfo(public_path() . '/uploads/' . $file->document_path));