我目前正在使用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
任何人都可以向为什么会发生这种情况吗?我完全被困了!
感谢您的帮助,
Alex
aha!事实证明,我需要在存储:: put()函数上使用file_get_contents($ aSset)。现在一切都说得通了!:)