我的程序使用PHP将各种大小的图像上传到MySQL数据库的blob字段。我能够成功上传不超过1MB及以上的不同尺寸。我的问题是,当我显示它们时,我能够显示小于10KB的图像。对于较大的图像,显示错误.....无法显示,因为它包含错误(在Firefox中),而在Chrome中,它只显示图像占位符。我尝试了很多技巧,而且我到处都是Google搜索。我编辑了php.ini和my.ini。我的程序是一个Intranet应用程序,一次只有不到50个用户。这是用于显示图像的脚本:为什么有些图像不能渲染
如果我删除标头('Content-Type:'。$ resource_type),它会将二进制代码转储到屏幕上。我已经将MySQL数据包大小增加到100MB,问题依然存在。
$d_id= $_GET['k'];$query="";$query_handle=0;$row="";$no_of_rows=0;
$query="SELECT * FROM tdoc ";
$query.=" WHERE ucase(trim(fsha_doc_key))='".strtoupper(trim($d_id))."' ";
$query_handle=mysql_query($query,$conn_handle);
if(!$query_handle) {$error_flag=1;echo '<br />Unable to execute query to Extract Resource CODE:FREF';}
if($query_handle) $no_of_rows=mysql_num_rows($query_handle);
if(($query_handle)&&($no_of_rows<=0)) {$error_flag=1;echo '<br />The Exact Resource: '.strip_tags($d_id).' NOT found ';}
if(($query_handle)&&($no_of_rows>0)){
$row=mysql_fetch_assoc($query_handle);
$resource_type=trim($row['ftype']);
$resource_size=$row['fsize'];
$resource_h=$row['fheight'];
$resource_w=$row['fwidth'];
$d_resource=$row['fdoc'];
header('Content-Type: '.$resource_type);
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-Length: '.filesize($d_resource));
header('Content-height: '.$resource_h);
header('Content-width: '.$resource_w);
echo stripslashes(base64_decode($d_resource));
}
我已经读到这里关于这个错误完全的帖子,但没有解决我的具体问题,因为我的是显示小尺寸的图像,但不是图像达到和超过10KB。 10kb与我稍后上传的预计平均图像大小相差甚远。请帮忙。
这看起来像你可能会打开自己的SQL注入? – John
只是一个建议,你不应该将整个文件保存在你的数据库中,你应该将它保存在你的服务器上的一个目录中,然后引用msql文件中的链接... –