图像滑块上没有显示图像

时间:2016-05-09 10:26:58

标签: php jquery html sql image

您好我正在创建动态图像滑块但图像未显示。我可以在文件目录中上传图片。如果数据库是问题或什么,我不知道问题是什么。我是html和css的新手也是php。有人能告诉我不显示图像的原因是什么吗?

这里是图像没有显示但我可以将文件上传到我的图库文件目录。 enter image description here

这是我的数据库sql。 enter image description here

这是我的PHP代码。

<?php
//for connecting db
include('connect.php');
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}
else
{
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"gallery/" . $_FILES["image"]["name"]);
$photo="gallery/" . $_FILES["image"]["name"];


$query = mysqli_query($mysqli, "INSERT INTO images(photo)VALUES('$photo')");
$result = $query; 

echo '<script type="text/javascript">alert("image successfully uploaded ");window.location=\'index.php\';</script>';
}
?>
<!DOCTYPE html>
<html>
    <head>
        <link href="css/style.css" rel="stylesheet" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
        <script src="js/slider.js"></script>
        <script>
        $(document).ready(function () {
        $('.flexslider').flexslider({
        animation: 'fade',
        controlsContainer: '.flexslider'
        });
        });
        </script>
    </head>
    <body>
    <div class="container">
    <form class="form" action="" method="POST" enctype="multipart/form-data">
        <div class="image">
            <p>Upload images and try your self </p>
        <div class="col-sm-4">
              <input class="form-control" id="image" name="image" type="file" onchange='AlertFilesize();'/>
              <input type="submit" value="image"/>
            </div>
        </div>
        </form>
        <div class="flexslider">
            <ul class="slides">
                <?php
                    // Creating query to fetch images from database.
                   $query = mysqli_query($mysqli, "SELECT * from images order by id desc limit 5");
                    $result = $query;
                    while($r = mysqli_fetch_array($result)){ 
                ?>
                    <li>
                    <img src="<?php echo $r['photo'];?>" width="400px" height="300px"/>
                    </li>
                <?php 
                } 
                ?>
            </ul>
        </div>
    </div>
    </body>
</html>

这是我的connect.php

<?php
// hostname or ip of server
$servername='localhost';
// username and password to log onto db server
$dbusername='root';
$dbpassword='';
// name of database
$dbname='pegasus';

////////////// Do not  edit below/////////
$mysqli = new mysqli($servername,$dbusername,$dbpassword,$dbname);
if($mysqli->connect_errno){
    printf("Connect failed: %s\n", $mysql->connect_error);
    exit();
}

?>

1 个答案:

答案 0 :(得分:1)

图像显示您的列名称是图像,并且您按列名称照片提取记录。

只需更改

class Balance(Document):
    id = UUIDField()
    creation_date = DateTimeField(auto_now_on_insert=True)
    gross_balance = FloatField(required=True, min_value=0, default=0)
    balances_description = StringField(required=True, max_length=255)
    stake_holder = #FK to Stakeholder

class Stakeholder(Document):
    ...

<img src="<?php echo $r['photo'];?>" width="400px" height="300px"/>