我正在使用 laravel 并且使用 MySQL 數(shù)據(jù)庫。我將圖像作為 blob 保存到數(shù)據(jù)庫中,如下所示:$path = $data->file;$image = file_get_contents($path);$base64 = base64_encode($image);DB::connection('mysql_live')->table('users_comments_files')->insert( ['comment_id' => $data->comment_id, 'filename' => 'TEST', 'date_added' => date("Y-m-d H:i:s"), 'date_modified' => date("Y-m-d H:i:s"), 'filetype' => 'image/png', 'file' => $base64]);文件列中有一些數(shù)據(jù),所以我認為它有效?,F(xiàn)在我想在 iframe 或 atm 中顯示圖像。創(chuàng)建一個網(wǎng)址。這是我如何嘗試在視圖中創(chuàng)建/顯示 blob 的相關(guān)部分:return '<img data="data:' . $result->filetype . ';base64,' . $result->file . '" type="' . $result->filetype . '" class="object-elem"></img>我嘗試像這樣顯示它們:$result = DB::connection('mysql_live')->table('users_comments_files')->where('id', $element_id)->first();$object_type = 'object';if (str_contains($result->filetype, 'image')) { $object_type = 'img';}return '<' . $object_type . ' data="data:' . $result->filetype . ';base64,' . $result->file . '" type="' . $result->filetype . '" class="object-elem"></' . $object_type . '> <style> body { background-color:#3a3a3a; } .object-elem { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; min-width: 100px; min-height: 100px; }</style>'; 我沒有收到任何錯誤,但結(jié)果總是一個白色方塊/立方體:
1 回答

猛跑小豬
TA貢獻1858條經(jīng)驗 獲得超8個贊
您需要刪除雙Base64編碼,并填寫屬性src未data在<img>標簽
<' . $object_type . ($object_type == 'img'?'src':'data') . '
="data:' . $result->filetype . ';base64, ' . $result->file . '" type="' . $result->filetype . '" class="object-elem">
</' . $object_type . '>
- 1 回答
- 0 關(guān)注
- 236 瀏覽
添加回答
舉報
0/150
提交
取消