【问题标题】:Laravel Corrupted Files - Files contain temporary path?Laravel 损坏的文件 - 文件包含临时路径?
【发布时间】:2017-07-19 14:15:00
【问题描述】:

我目前正在使用 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

谁能解释为什么会发生这种情况?我完全被难住了!

感谢您的帮助,

亚历克斯

【问题讨论】:

    标签: php laravel file upload flysystem


    【解决方案1】:

    啊哈!原来我需要在 Storage::put() 函数上使用 file_get_contents($asset) 。现在一切都说得通了! :)

    【讨论】:

    • 解释一下,例如?还有……嗯?
    猜你喜欢
    • 2012-04-11
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 2022-10-05
    相关资源
    最近更新 更多