1

開発環境でデータベースからイメージをロードしようとしていたため、イメージをロードできず、代わりに「エラーが含まれているためイメージを表示できません」というエラーが返されました。

<?php

require_once 'app_config.php';                 //app config file
require_once 'database_connection.php';        //database connection

try{
//Get the image id.
if(!isset($_REQUEST['image_id'])){
handle_error("No image to load was specified.");
}
$image_id = $_REQUEST['image_id'];

//Build the SELECT statement
$select_query = sprintf("SELECT * FROM images WHERE image_id = %d", $image_id);

//Run the query
$result = mysql_query($select_query);

//Get the result and handle errors from getting no result
if(mysql_num_rows($result) == 0){
  handle_error("We couldn't find the requested image.", "No image found with and    ID of " . $image_id . ".");
 }
 $image = mysql_fetch_array($result);

//Tell the browser what's coming with headers
header('Content-type: ' . $image['mime_type']);
header('Content-length: ' . $image['file_size']);

echo $image['image_data']; 
}catch(Exception $exc){
  handle_error("Something went wrong loading your image.",
             "Error loading image: " . $exc->getMessage());
}

?>
4

3 に答える 3

0

画像が CMYK 色空間を使用している場合、完全に正当な画像でこのエラーが発生しました。これは、多くの/ほとんどのブラウザーがサポートしていません。元の画像を (PHP/DB プロセスなしで) ブラウザーに直接ロードしてみて、同じエラーがスローされるかどうかを確認してください。その場合は、画像エディター (またはサーバー側で行う場合は imagemagick) を使用して画像を RGB に変換する必要があります。

これは、特定の FF 拡張機能、つまり Skype の既知の問題でもあります。拡張機能または別のブラウザーを無効にして、この問題が影響するかどうかを確認してください。

于 2013-09-17T02:49:51.153 に答える
0
$sql = mysql_query("SELECT * FROM images WHERE image_id = %d", $image_id");


header("Content-Type: image/jpeg");
$row = mysql_fetch_row($sql);

$im=imagecreatefromstring($row[$i]);
imagejpeg($im).'<br>';


echo("<img src=\"$im.$name\" width=\"200\" height=\"150\" />");

これはうまくいくかもしれません..

于 2013-09-17T02:44:28.407 に答える