0 レビュー
1 回答
php-base64_decodeを使用して画像を生成しようとしたときにエラーが発生しました
base64_decode
を使用してpng拡張子の画像を生成しようとしていますが、生成されたpng画像が間違っており、「無効な画像」と表示されています。
私のコードは以下です
$ base_64 = $ this-> input-> post('base_64');
$ decode_base_64 = base64_decode($ base_64);
$ result = file_put_contents('directory / toSaveImage/'。$id。'.png'、$ decode_base_64);
ソリューションを検索しているときに、$result変数の前に追加してみました。
header("Content-type: image/png");
私もこの行を試しました
$ decode_base_64 = base64_decode(base64_encode($ base_64));
誰か助けてくれませんか?
わからない
0
レビュー
答え :
解決策:
これがあなたの答えです:
<?php
$base64 = $this->input->post('base_64');
$base64 = str_replace('data:image/png;base64,', '', $base64);
file_put_contents("directory/toSaveImage/{$id}.png", base64_decode($base64));
data:image/png;base64,
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。