在php中显示图像时出错
我在php中显示图像时出错,我的脚本过去可以正常工作,但现在不行:( 我的剧本是这样的:在php中显示图像时出错,php,image,upload,photo,Php,Image,Upload,Photo,我在php中显示图像时出错,我的脚本过去可以正常工作,但现在不行:( 我的剧本是这样的: $image_id = intval($_REQUEST['id']); //Query database for our images data and grab it fromt the array returned $result = mysql_query(sprintf("SELECT data, file_size, mime_type FROM _system_image WHERE
$image_id = intval($_REQUEST['id']);
//Query database for our images data and grab it fromt the array returned
$result = mysql_query(sprintf("SELECT data, file_size, mime_type FROM _system_image WHERE id = %d;", $image_id));
$row = mysql_fetch_array($result);
//Set the headers so the browser knows an image is coming and then echo out the data
header("Content-type: " . $row['mime_type']);
header("Content-length: " . $row['file_size']);
echo $row['data'];
exit();
我上传照片的脚本是:
//Create an array of potential errors for uploading images
$image_uploading_errors = array(1 => 'Maximum file size in php.ini exceeded',
2 => 'Maximum file size in HTML form exceeded',
3 => 'Only part of the file was uploaded',
4 => 'No file was selected to upload.');
//Get the filename and size (validation of size is done in html part!)
$filename = $_FILES[SINGLE_IMAGE_UPLOAD_NAME]['name'];
$img_size = $_FILES[SINGLE_IMAGE_UPLOAD_NAME]['size'];
//Use the tmp name, to 'getimagesize' which returns an array of info (not just images size!) and also to get the data from the image
$info = getimagesize($_FILES[SINGLE_IMAGE_UPLOAD_NAME]['tmp_name']);
$data = file_get_contents($_FILES[SINGLE_IMAGE_UPLOAD_NAME]['tmp_name']);
//Get the mime type from the img_size (an array of info)
$mime_type = $info['mime'];
//Put all the info into a new image object
//(img_id, album_id, album_pos, name, low_res_mime, low_res_size, high_res_mime, high_res_size, available_sizes, date_uploaded, date taken, caption)
$img = new Image(NULL, NULL, NULL, $filename, NULL, NULL, $mime_type, $file_size, NULL, new DateTime(), NULL, NULL);
$img->set_high_res_data($data);
//Return the image!
return $img;
使用的Image类是我自己编写的,所有变量(如$mime_type)都正确地进入数据库
我觉得这可能是一个重复的问题,但我已经看了这里,没有一个解决方案(我发现)是有用的
编辑:
错误为“图像“…”无法显示,因为它包含错误。“其中“…”是文件名
我通常尝试用html显示图像:wher%d是整数
问题是图像根本没有被弄脏
SINGLE_IMAGE_UPLOAD_NAME是$文件中数组键的常量
编辑:
这不是一个真正的解决方案,但我改为使用此问题中的方法来显示图像,现在它可以工作了:
错误是什么?错误来自哪里?您想从我们这里得到什么?错误是“图像“…”无法显示,因为它包含错误。”其中,“…”是文件名。它来自于我试图直接访问脚本时,它通常是这样访问的,但这不会给出任何错误,它只是不会显示它。我希望有人会有一个为什么图像根本不会显示。对不起,我现在很累,所以我应该已经说过了。对h有什么建议吗我该怎么表达这个问题,我想不出该说什么?@Madbreaks我也不明白你的问题,因为它不是一个问题(我承认它不是特别描述性的,但它仍然是准确的)由于其他人一直在发布“非问题”,尤其是当你之前发布了“不是问题”的内容时!这是一个问答网站。如果你不确定如何正确提问,请阅读常见问题解答: