Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP页面作为图像源?_Php_Image_Mysqli - Fatal编程技术网

PHP页面作为图像源?

PHP页面作为图像源?,php,image,mysqli,Php,Image,Mysqli,正如标题所示,我目前正在使用PHP页面作为图像标记的“src”属性 图像以MEDIUMBLOBs的形式存储在“Questions”MySQL表中(还有其他更好的存储图像的方法,但不幸的是,我在这里没有回旋的余地) 我像这样回显图像: echo("<img src=\"teacherPageQuestionsImage.php?id=" . $_row["Question_ID"] . "\">"); 那么到底是什么造成了问题呢?为什么图像在Chrome桌面上显示良好,但在其他浏览

正如标题所示,我目前正在使用PHP页面作为图像标记的“src”属性

图像以MEDIUMBLOBs的形式存储在“Questions”MySQL表中(还有其他更好的存储图像的方法,但不幸的是,我在这里没有回旋的余地)

我像这样回显图像:

 echo("<img src=\"teacherPageQuestionsImage.php?id=" . $_row["Question_ID"] . "\">");

那么到底是什么造成了问题呢?为什么图像在Chrome桌面上显示良好,但在其他浏览器和移动Chrome(Android)上根本无法渲染.

您是否发送了正确的图像标题响应,以告知浏览器您将要显示的内容是图像类型X?浏览器控制台中出现任何错误时,它不工作?尝试直接在浏览器中打开图像-当您在未内联显示图像的浏览器中运行图像时会发生什么情况?@OliverQueen您是指这一行吗<代码>标题(“内容类型:图像/jpeg”)您确定图像实际上是jpeg格式的吗?也许是png/gif?
<?php

require 'databaseConnect.php';

session_start();

if (!isset($_SESSION['valid_teacher']))
{
    header("Location:teacherLoginPage.php");
}

if(isset($_GET['id']))
{
    $_questionID = $_GET['id'];

    // Open DB Connection
    $_conn = databaseConnect();

    $_stmt = $_conn->prepare("SELECT Question_Image FROM Question WHERE Question_ID=?");
    $_stmt->bind_param("i",$_questionID);

    $_stmt->execute();
    $_stmt->store_result();
    $_stmt->bind_result($_image);
    $_stmt->fetch();

    // Close DB Connection
    $_conn->close();

    header("Content-Type: image/jpeg");
    echo($_image);   
}

?>
$_imagePost = file_get_contents($_FILES['_imagePost']['tmp_name']);

// Open DB Connection
$_conn = databaseConnect();

$_stmt = $_conn->prepare("INSERT INTO Question (Question_Type, Question_Text, Question_Answer, Question_UseImage, Question_Image) VALUES (?, ?, ?, ?, ?)");
$_stmt->bind_param("sssib", $_typePost, $_textPost, $_answerPost, $_useImagePost, $_null);
$_stmt->send_long_data(4,$_imagePost);
$_stmt->execute();

$_idPost = $_conn->insert_id;

// Close DB Connection
$_conn->close();