【发布时间】:2012-09-05 18:43:15
【问题描述】:
要保存我正在使用的图像:
$image_bin = addslashes(file_get_contents($img_url));
mysql_query('INSERT INTO images
(image_filename, image_type, image_bin)
VALUES
("file.jpg", "image/jpeg", "'.$image_bin.'")');
显示:
$qry = 'SELECT image_filename, image_type, image_bin
FROM images
WHERE image_id = 1';
$result = mysql_query($qry);
$row = mysql_fetch_row($result);
header('Content-type: '.$row['image_type']);
echo stripslashes($row['image_bin']);
图像已保存到数据库,但图像尺寸变大。 并且图像颜色变得有些损坏。
例如打开开发者工具的 Chrome 中的图片截图: screensho url
有人知道我做错了什么吗?
【问题讨论】:
-
尝试使用
mysql_real_escape_string而不是addslashes -
@halfer 确实,查询中应该有一些 proper 转义。但我认为这不是问题的原因。
-
菲利普,结果是一样的。对我来说奇怪的是,当我使用相同的方法上传文件时,一切都很顺利:/
-
如果出现转义问题,则图像根本不会打印
标签: php mysql image escaping store