-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 に答える