从文件夹调用图像的编码问题

时间:2017-01-02 19:30:23

标签: php

我有一个问题,现在没有在评论部分加载图片。它工作正常。我将图像保存到文件夹,上传的文件名是uniqid()。评论部分实际上工作正常,它只是我遇到问题的缩略图。使用CSS调整图像大小,因此没有缩略图文件。图像工作得很好,现在我得到了一个破碎的图像链接评论。有没有人看到这个代码有什么问题?

<?php

function setComments($conn) {
if (isset ($_POST['commentSubmit'])) {
    $uid = $_POST['uid'];
    $date = $_POST['date'];
    $message = $_POST['message'];
    $file_name = $_FILES['image']['name'];

    $sql = "INSERT INTO comments (uid, date, message, images) values ('$uid','$date','$message','$file_name')";
    $result = mysqli_query($conn, $sql);
    }
}       
    if(isset($_FILES['image'])){
        $errors= array();
        $file_name = $_FILES['image']['name'];
        $file_size = $_FILES['image']['size'];
        $file_tmp = $_FILES['image']['tmp_name'];
        $file_type = $_FILES['image']['type'];
        $tmp = explode('.', $file_name);
        $file_ext =  end($tmp);
        $new_image_name = 'image_' . date('Y-m-d-H-i-s') . '_' . uniqid() . '.jpg';

        $expensions= array("jpeg","jpg","png"."gif");

        if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG, GIF, or PNG file.";
        }

        if($file_size > 2097152) {
         $errors[]='File size must be excately 2 MB';
        }

        if(empty($errors)==true) {
            move_uploaded_file($file_tmp,"uploads/".$new_image_name);
            echo "Successfully uploaded file!";

        }else{
            print_r($errors);
    }

}
function getComments($conn) {    

    $sql = "SELECT * FROM comments ORDER BY date DESC LIMIT 10";
    $result = mysqli_query($conn, $sql);
    while ($row = $result->fetch_assoc()) {

        echo $row['uid']."<br>";
        echo $row['date']."<br><br>";
        echo "<a href=\"uploads/{$row['images']}\"target=\"_blank\">   <img class='thumb' src=\"uploads/{$row['images']}\" />    </a>"."<br><br>";
        echo nl2br($row['message'])."<br><br>";

    }
}

1 个答案:

答案 0 :(得分:0)

不要在src中使用{}只使用$ row [&#39; images&#39;]它应该有效