dopcpc9207 2017-02-28 06:40
浏览 57
已采纳

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

I'm currently developing a content management system using Laravel, however I am coming across a very strange issue...

//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;
  }
}

The above code successfully uploads the file and places it into the directory, and then proceeds to save the filename in the database, however the file becomes corrupt.

When uploading a test.txt file, the upload succeeds, however when examined on the server, the file contents is changed to the temporary path (see below)?????

/tmp/phpkTe9NX

Can anyone shed some light onto why this would happen? I'm completely stumped!

Thanks for your help,

Alex

  • 写回答

1条回答 默认 最新

  • doulou0882 2017-02-28 07:07
    关注

    Aha! Turns out I needed to use file_get_contents($asset) on the Storage::put() function. It all makes sense now! :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部