来自db的图像未完成

时间:2021-12-15 16:33:59

I am trying get image data from microsoft SQL Server database from column with datatype image, show it and store to file. But some images (10%) are not completed. In browser are they rendered only as half or 1/3 from top. Every time 'problematic' images are the same and broke way is the same too.

我正在尝试从具有数据类型图像的列获取Microsoft SQL Server数据库中的图像数据,显示它并存储到文件。但有些图像(10%)尚未完成。在浏览器中,它们仅从顶部渲染为一半或1/3。每次'有问题'的图像都是一样的,破碎的方式也是一样的。

Problematic images i was trying show and store on 2 different servers

有问题的图像我正在尝试展示和存储在2个不同的服务器上

  • Not working server - PHP Version 5.5.19-1~dotdeb.1 (cca 10% images broken)
  • 不工作的服务器 - PHP版本5.5.19-1~dotdeb.1(cca 10%图像坏了)
  • Working server - PHP Version 5.2.17 (all images ok)
  • 工作服务器 - PHP版本5.2.17(所有图像都可以)

If i use on both servers this:

如果我在两台服务器上使用这个:

var_dump(base64_encode($row['data'], "UTF-8"));

It looks like part of image is missing - string is shorter.

看起来图像的一部分缺失 - 字符串更短。

Is this some data interpretation/converting issue?

这是一些数据解释/转换问题吗?

If i use on fetched data iconv_get_encoding ormb_detect_encoding both return false on both servers...

如果我在获取的数据上使用iconv_get_encoding ormb_detect_encoding,则两个服务器都返回false ...

My code:

我的代码:

$conn = mssql_connect ('xxx.xxx.xxx.xxx' , 'xxxxxxxxx', 'xxxxxxxxxxxxxxxxx' );

if (!$conn) {
    echo "<p style='color: red'>error in connection db! id: ".$id."</p>";
} else {
    mssql_select_db('CK', $conn);
    echo "<p style='color: green'>connection ok for id: ".$id."</p>";
}

$result = mssql_query(
    "SELECT k.data FROM KatG k 
     WHERE k.auto='".$id."'
     ORDER BY k.attr DESC");

$row = mssql_fetch_assoc($result);


$imageData = base64_encode($row['data']);
$src = 'data: image/jpeg;base64,'.$imageData;
$img = '<img style="height: 60px; float: right;" src="'. $src. '">';

echo $img."<p>OK i get data!</p> <hr>";

If i save this image like this: (without base64_encode function)

如果我像这样保存这个图像:(没有base64_encode函数)

$im = imagecreatefromstring($row['data']);
imagejpeg($im, $path);

Picture is broken same way as displayed image in browser.

图片与浏览器中显示的图片相同。

1 个解决方案

#1


0  

Was necessary increase TEXTSIZE before mssql_fetch_assoc and images are ok...

在mssql_fetch_assoc和图像确定之前必须增加TEXTSIZE ...

mssql_query('SET TEXTSIZE 10000000');

So difference was in php.ini there you can set this value pernament

所以在php.ini中有区别,你可以设置这个值

mssql.textlimit = 10000000
mssql.textsize = 10000000

#1


0  

Was necessary increase TEXTSIZE before mssql_fetch_assoc and images are ok...

在mssql_fetch_assoc和图像确定之前必须增加TEXTSIZE ...

mssql_query('SET TEXTSIZE 10000000');

So difference was in php.ini there you can set this value pernament

所以在php.ini中有区别,你可以设置这个值

mssql.textlimit = 10000000
mssql.textsize = 10000000