gpt4 book ai didi

php - 无法在 PHP 中显示图像

转载 作者:行者123 更新时间:2023-11-29 14:43:04 26 4
gpt4 key购买 nike

这是我的图像显示代码 -

$username = "xxxxxxxx";
$password = "xxxxxxxx";
$host = "000.001.000.000";
$database = "xxxxxxxx";

@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$query = mysql_query("SELECT mimetype, Image FROM table ORDER BY id DESC LIMIT 0,1");
$row = mysql_fetch_array($query);
$content = $row['Image'];
header('Content-type: image/jpg');
echo $content;

这是我遇到的错误

图像“http://www...”无法显示,因为它包含错误。

出了什么问题? mysql中字段的数据类型是mediumblob

最佳答案

好的,首先测试一下,看看发生了什么:

$username = "xxxxxxxx";
$password = "xxxxxxxx";
$host = "000.001.000.000";
$database = "xxxxxxxx";

if( !mysql_connect($host, $username, $password) )
die( 'Unable to connect to Server: '.mysql_error() );
if( !mysql_select_db($database) )
die( 'Can not select the Database: '.mysql_error() );

$query = mysql_query( "SELECT mimetype, Image FROM table ORDER BY id DESC LIMIT 0,1" );

if( !$query )
die( 'Query Failed: '.mysql_error() );
if( mysql_num_rows( $query )==0 )
die( 'Query Returned No Records' );

$row = mysql_fetch_array($query);

echo '<pre>';
var_dump( $row );
echo '</pre>';

这应该显示数据库的结果,或者错误消息。如果您看到错误消息,请纠正导致该错误的原因...

上面只返回数据库行内容之后:

$username = "xxxxxxxx";
$password = "xxxxxxxx";
$host = "000.001.000.000";
$database = "xxxxxxxx";

if( !mysql_connect($host, $username, $password) )
die( 'Unable to connect to Server: '.mysql_error() );
if( !mysql_select_db($database) )
die( 'Can not select the Database: '.mysql_error() );

$query = mysql_query( "SELECT mimetype, Image FROM table ORDER BY id DESC LIMIT 0,1" );

if( !$query )
die( 'Query Failed: '.mysql_error() );
if( mysql_num_rows( $query )==0 )
die( 'Query Returned No Records' );

$row = mysql_fetch_array($query);

header( 'Content-type: '.$row['mimetype'] );
echo $row['Image'];

(假设 mimetype 字段类似于“image/jpg”)

关于php - 无法在 PHP 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7591546/

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