2013-10-14 11:26
浏览 72


I try to show an image stored in a database. I wrote it with

$image = file_get_contents($testPfad);
$dateigroesse = filesize($testPfad);

$arrData = unpack("H*hex", $image); 
$data_string = "0x".$arrData['hex']; 

$sql = "INSERT INTO EHS.dbo.T_Signaturen (UnterschriftsDateiName,UnterschriftsBild,Dateigroesse,terminID) VALUES (
        echo '<hr>'.$sql;

With this code I output the image.

header("Content-type: image/jpeg");  
$query = "SELECT Dateigroesse, CONVERT(varchar(max), UnterschriftsBild) as content_data FROM EHS.dbo.T_Signaturen WHERE ID = '10'"; 
$result = query($query);
$content = $result[1]["content_data"];       
$filesize = $result[1]["Dateigroesse"]; 

$content = substr ($content, 2);             // entfernt 0x
$content = pack("H*", $content); 
print $content;  

Everything works fine but only a part of the image is shown. I reduced the image size from 20kb to 2kb and much more is shown so I think ANYWHERE the binary data is cut. The Database Column is a varbinary(max)

Please let us not discuss wether it is rational to store blob in databases :) :)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudong8713 2013-10-15 08:19

    The solution was to increase the max accepted string length of odbc in php.ini. It was set to 4069 chars

    打赏 评论
  • drudmb2594 2013-10-14 11:34
    • did you try to define your column as BLOB (up to 2 GB)?
    • are you sure, that the complete image is stored (maybe that function is wrong)
    打赏 评论

相关推荐 更多相似问题