dopcpc9207
2017-02-28 14:40
浏览 51
已采纳

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

图片转代码服务由CSDN问答提供 功能建议

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

  //如果提供了资产
 $ asset = $ request-> file('asset'); 
if  ($ asset){
 //设置文件名。
 $ fileName = $ asset-> getClientOriginalName(); 
 //如果我们可以移动上传资产。
 if(Storage :: disk('  local') - > put('presentation_assets /'.$ fileName,$ asset)){
 //将文件名保存在数据库中。
 $ presentation-> asset = $ fileName; 
} 
 上述代码成功上传文件并将其放入目录中,然后继续将文件名保存在数据库中,但文件已损坏。<}   
 
 

/ p>

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

  / tmp / phpkTe9NX 
   
 
 

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

感谢您的帮助,

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! :)

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题