Laravel损坏的文件 - 文件包含临时路径?

时间:2017-02-28 14:40:24

标签: php laravel file upload flysystem

我目前正在使用Laravel开发内容管理系统,但是我遇到了一个非常奇怪的问题......

//If an asset was provided
$asset = $request->file('asset');
if($asset) {
  //Set the file name.
  $fileName = $asset->getClientOriginalName();
  //If we could move the uplaoded asset.
  if(Storage::disk('local')->put('presentation_assets/'.$fileName, $asset)) {
    //Save the file name in the database.
    $presentation->asset = $fileName;
  }
}

上面的代码成功上传文件并将其放入目录,然后继续将文件名保存在数据库中,但文件已损坏。

上传test.txt文件时,上传成功,但是在服务器上检查时,文件内容会更改为临时路径(见下文)?????

/tmp/phpkTe9NX

有人能说清楚为什么会这样吗?我完全难过了!

感谢您的帮助,

亚历

1 个答案:

答案 0 :(得分:1)

啊哈!结果我需要在Storage :: put()函数上使用file_get_contents($ asset)。这下全说通了! :)