不知道是不是 5.5 的一个 Bug?

使用以下这种追加内容的方式保存的文件不正常,无法打开。

Storage::disk('local')->append($fileRelativePath, file_get_contents($chunk->getRealPath()))

但使用原生的这种方式就没问题,可以正常识别和打开。

file_put_contents($fileAbsolutePath, file_get_contents($chunk->getRealPath()), FILE_APPEND)

两次运行的代码只有上面的差别,两个文件保存后的大小也有些微小的差别,真是见鬼了,我已经提交了这个issue,有谁知道是哪方面的问题吗?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
leo
最佳答案

Storage::disk('local')->append($fileRelativePath, file_get_contents($chunk->getRealPath()), '')

7年前 评论
讨论数量: 4

补上复现代码,有没有老铁测试一下

Route::post('/upload', function () {
    # upload a file in jpg format
    $chunk = request()->file('chunk');
    touch('/path-to-laravel/storage/app/test.jpg');
    # broken file
    \Illuminate\Support\Facades\Storage::disk('local')->append('test.jpg', @file_get_contents($chunk->getRealPath()));
    # intact file
    //@file_put_contents('/path-to-laravel/storage/app/test.jpg', @file_get_contents($chunk->getRealPath()), FILE_APPEND);
});
7年前 评论
leo

Storage::disk('local')->append($fileRelativePath, file_get_contents($chunk->getRealPath()), '')

7年前 评论
leo

https://github.com/laravel/framework/blob/...

append 方法默认情况下会添加换行符

7年前 评论

@leo 感谢!原来是这个问题,掉坑里去了?

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!