最佳答案 存储图像数据时如何对其进行编码?我建议您-6ren">
gpt4 book ai didi

php - 图像无法显示,因为它包含错误,当我删除以下行时显示文本 "header(' Content-type : ' ...."

转载 作者:行者123 更新时间:2023-11-30 23:13:41 25 4
gpt4 key购买 nike

当我试图从我的开发环境中的数据库加载图像时,无法加载图像,而是返回错误消息“无法显示图像,因为它包含错误。”

<?php

require_once 'app_config.php'; //app config file
require_once 'database_connection.php'; //database connection

try{
//Get the image id.
if(!isset($_REQUEST['image_id'])){
handle_error("No image to load was specified.");
}
$image_id = $_REQUEST['image_id'];

//Build the SELECT statement
$select_query = sprintf("SELECT * FROM images WHERE image_id = %d", $image_id);

//Run the query
$result = mysql_query($select_query);

//Get the result and handle errors from getting no result
if(mysql_num_rows($result) == 0){
handle_error("We couldn't find the requested image.", "No image found with and ID of " . $image_id . ".");
}
$image = mysql_fetch_array($result);

//Tell the browser what's coming with headers
header('Content-type: ' . $image['mime_type']);
header('Content-length: ' . $image['file_size']);

echo $image['image_data'];
}catch(Exception $exc){
handle_error("Something went wrong loading your image.",
"Error loading image: " . $exc->getMessage());
}

?>

最佳答案

存储图像数据时如何对其进行编码?我建议您尝试 base64_decode() 它,因为这是传输/存储图像数据的常见方式。

echo base64_decode($image['image_data']);
exit;

关于php - 图像无法显示,因为它包含错误,当我删除以下行时显示文本 "header(' Content-type : ' ....",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18839082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com