dopcpc9207 2017-02-28 14: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 15:07
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?