Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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中没有显示来自MySqL的图像_Php_Mysql_Image - Fatal编程技术网

在PHP中没有显示来自MySqL的图像

在PHP中没有显示来自MySqL的图像,php,mysql,image,Php,Mysql,Image,我试图通过将图像保存在数据库[MySql]中来显示php页面中的图像,但当我检索它时,它没有显示图像。 但是,当我在MySql中单击它时,我可以看到该图像,但它没有显示在php文件中 图像表: id INT 图像斑点 index.php <html> <head> <title>Uploade an image</title> </head> <body> <form action="test_ima

我试图通过将图像保存在数据库[MySql]中来显示php页面中的图像,但当我检索它时,它没有显示图像。 但是,当我在MySql中单击它时,我可以看到该图像,但它没有显示在php文件中

图像表: id INT

图像斑点 index.php

<html>
<head>
    <title>Uploade an image</title>
</head>

<body>
    <form action="test_image.php" method="POST" enctype="multipart/form-data">
        File: 
        <input type="file" name="image"> <input type="submit" value="Uploade">
    </form>

<?php
mysql_connect("", "", "")
or die("<p>Error connecting to database: " . mysql_error() . "</p>");

mysql_select_db("test")
or die("<p>Error selecting the database: " . mysql_error() . "</p>");

// file propoerties
$file = $_FILES['image']['tmp_name'];

if(!isset($file))
    echo "Please select an image.";
else 
{
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); 
    $image_size = getimagesize($_FILES['image']['tmp_name']);

    if($image_size == FALSE)
        echo "That's not an image";
    else
    {
        if(!$insert = mysql_query("INSERT INTO Images (image) VALUES ('$image')"))
            echo "Problem uploading image.";
        else
        {
            $lastid = mysql_insert_id(); 
            echo "Image uploaded <p /> Your image: <p /> <img  width='500' height='500'  src=getimage.php?id=$lastid>";
        }
    }
 }

?>

</body>
</html>
getimage.php

<?php
mysql_connect("", "", "")
or die("<p>Error connecting to database: " . mysql_error() . "</p>");

mysql_select_db("test")
or die("<p>Error selecting the database: " . mysql_error() . "</p>");

$id = addslashes($_REQUEST['id']);

$image = mysql_query("SELECT * FROM Images WHERE id = $id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];

header("Content-type: image/jpeg");

echo $image;
?>
我可以上传图片,但我无法检索


谢谢,

您需要使用img html元素来查看图像

比如说 src这里是保存图像文件的地方

<img src="images/yoursavedimagenameindatabase" width="" height=""> 

然后您可以在view中查看保存的图像

首先,我建议您切换到mysql以外的其他版本,试试mysqli或PDO。Mysql已弃用。您从getimage.php脚本获得的确切输出是什么?尝试将图像blob保存为base64_encode,并在getimage.php脚本中使用base64_decode我现在无法切换!!我得到一个小问号,而不是图片。如何将其保存为base64???@FinalProject迁移并不困难,甚至有很多方法可以做到这一点。您真的应该切换到MySQLi,因为基本的MySQL扩展是这样的。请调试您的代码,并告诉我您遇到了什么错误,以便我可以帮助您
$path="images/.$image['image']."    
echo '<img width="100" height="66"  src="'.$path.'" />';