图片没有显示 - PHP

时间:2018-01-23 15:07:13

标签: php mysql image fetch

我试图显示图片,但是当我点击时它只显示文件名。我认为我的echo <img>有问题..如何在echo语句中编写图像标签..我也在网上发现了一些想法,但没有运气。任何帮助将非常感激。有什么想法吗?

 <?php
 //Create connection and select DB
        $conn= mysqli_connect("localhost","root", "", "upload_images");


if(isset($_POST["submit"]))
{
$file_name=$_FILES['fileToUpload']['name'];
$file_tmp=$_FILES['fileToUpload']['tmp_name'];
$file_size=$_FILES['fileToUpload']['size'];
$file_tmp=$_FILES['fileToUpload']['tmp_name'];
$file_error=$_FILES['fileToUpload']['error'];

$datetime=date("Y-m-d H:m:sa");

$target_path="D:\zak/";

 if(move_uploaded_file($file_tmp,$target_path.$file_name))
 {
  echo "Move Success";
}
  else
  {
    echo "Not Move";
  }

         //Insert image content into database
        $query = "INSERT into image_upload (image,created) VALUES ('$file_name','$datetime')";

       if (mysqli_query($conn,$query)) 
         {
          echo "Registered Sucessfully"."<br>";
         }
       else
         {
         echo"OOPS!! Try Again..";
         }


    $sql1="SELECT image FROM image_upload order by Id desc limit 1";
    $result=mysqli_query($conn,$sql1);
     if (!$result) {
       echo "Error";
     }else{
      echo "Fetced image";
     }

while ($row=mysqli_fetch_assoc($result)) {

$path= $row['image'];
 echo "<img src='$path' height='200' width='200'/>";

}
  }


?>

1 个答案:

答案 0 :(得分:0)

尝试使用表格输出图像,可能问题是在调用原始路径时使用$ path

 <td><img src="<?php echo $rows['image']?>" width='200px' height='200px'></td>