-1

要保存我正在使用的图像:

$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

有谁知道我可能做错了什么?

4

1 回答 1

4

尝试...

//use mysql real escape
$image_bin = mysql_real_escape_string(file_get_contents($img_url));
mysql_query('INSERT INTO ' . PREFIX . 'news_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 $row['image_bin']; //no stripslashes
于 2012-09-12T17:28:44.867 回答