简单的网页无法从MySQL数据库加载一些图像,有些效果很好

时间:2016-08-08 17:41:56

标签: php html mysql

我有一个简单的网页和一个数据库来上传和显示网页上的图像。但是,有些图片无法在网页上正确下载和显示,有些图片显示效果不错。我检查了我的数据库,每个图像都可以正确插入数据库。

我的PHP代码如下:

<?php
    ini_set('mysql.connect_timeout',10);
    ini_set('default_socket_timeout',5);

    include_once 'dbconnect.php';


?>



    <?php
    if(isset($_POST['btn_Upload_Image']))
    {   
        if(getimagesize($_FILES['image']['tmp_name']) == FALSE)
        {
            // echo "Please select an image.";
            ?>
                    <script>alert('Please select an image.');</script>
            <?php
        }
        else
        {
            $image= addslashes($_FILES['image']['tmp_name']);
            $Name= addslashes($_FILES['image']['name']);
            $image= file_get_contents($image);
            $image= base64_encode($image);
            saveimage($Name,$image);
         }

    }
    //displayimage();



    function saveimage($Name,$Image)
            {

                $qry="Insert into Clothing (Picture_Name,Picture_Storage) values ( '$Name','$Image')";

                // echo "$qry" ."</br>";
                $result=mysql_query($qry);
                if($result)
                {   
                    ?>
                    <script>alert('Image uploaded.');</script>
                    <?php
                }
                else
                {   
                    ?>
                    <script>alert('Image not uploaded.');</script>
                    <?php
                }
            }



    function displayimage()
            {   
                $qry = "Select * from Clothing";

                $result=mysql_query($qry);

                while($row = mysql_fetch_array($result))
                {
                    echo '<img height="200" width="200" src="data:image;base64,'.$row[Picture_Storage].' "> ';
                }
            }


?>



<html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Hello PeekABuy</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>


    <body>

    <div id="header">
        <div id="left">
        <label>Cropped Images </label>
        </div>
    </div>


<div id="body">
    <div id="Hotel-InfoForm">
        <form method="post" enctype="multipart/form-data">
            <center>
            <table align="center" width="40%" border="0">


            <tr>
            <td>
                <input type="file" name="image" />
                <br/>
                <br/>
                <input type="submit" name="btn_Upload_Image" value="Upload" />

            </td>   
            </tr>
            <center>
            </table>


            <br>
            <br>
            <br>
            <br>
            <br>
            <br>


        </form> 

            <?php
                displayimage();
            ?>

        <br> 
        <br>
        <br>
        <br>


        <hr>


    </div>
</div>




</body>
</html>

1:How webpage looks like; 2: Datatype of my database; 3: Inserting status

  

非常感谢!

0 个答案:

没有答案