BLOBを使用してDBにファイルを保存しようとしています。私はそれが非常に良い習慣ではないが、このようにする必要があることを知っている。Laravel 5のBLOBから変換されたPDFを読み込めませんか?
とにかく私が直面している問題は、返されたPDFファイルがもう読めないということです。しかし、docx、odt、txt、jpgなどの他のすべてのファイルは、BLOBから変換されたときに正常に動作しています。
public function store(Request $request)
{
$data = $request->all();
$file = $request->file('file');
$data['data'] = base64_encode(file_get_contents($file));
$data['extension'] = $file->guessExtension();
$data['name'] = $file->getClientOriginalName();
$file = $this->fileRepo->create($data);
return jsend()->success()
->message("Resource Created Successfully")
->data($file->toArray())
->get();
}
public function download($id)
{
$file = $this->fileRepo->find($id);
$randomDir = md5(time() . $file->id . $file->user->id . str_random());
mkdir(public_path() . '/files/' . $randomDir);
$path = public_path() . '/files/' . $randomDir . '/' . html_entity_decode($file->name);
file_put_contents($path, base64_decode($file->data));
header('Content-Description: File Transfer');
return response()->download($path);
}
どこが間違っていますか。どこにPDFをBLOBフィールドに保存する特別な方法がありますか?
多分コメントはこちら(http://stackoverflow.com/a/8991231/717181)ですか? – Luceos
私が知る限り、男は第三者のライブラリを使ってそれを長さ72の行でエンコードして解決したと言うことができますが、私のアプリケーションではそれをどうやって行うのか分かりません。特定の長さの行を使ってPHPでbase64でファイルをエンコードするには? – Rohan
アップロード前とダウンロード後のファイルの違いは? 'diff before.pdf after.pdf'のようなものです。 –