2016-07-08 132 views
1

下面是我的代码显示图像的信息,包括它的文件,但这不显示,我不知道为什么。请帮助我们。图像不显示使用php mysql

<?php 
     include('config/dbconnect.php'); 
     if(isset($_GET['id'])) 
     { 
      $id = $_GET['id']; 
      $sql = mysqli_query($con, "SELECT * FROM collage WHERE id = '$id'"); 
      while($row = mysqli_fetch_array($sql)) { 
        $name = $row['name']; 
        $content = $row['content']; 
        $size = $row['size']; 
        $type = $row['type']; 
        $date_upload = $row['date_upload']; 
        $file = $row['file']; 
      } 
     } 
?> 
<div class='body-content'> 
<div class='img-name-cont'><h3><?php echo $name; ?></h3></div> 
<div class='img-detail-cont'>upload: <?php echo $date_upload; ?><br>type: <?php echo $type; ?><br>size: <?php echo $size; ?>KB </div> 
<div class='img-file-cont'> 
<img src="img/collage/<?php echo $row['file'] ?>" style="width:130px; height:100%"></div> 
<div class='img-content-cont'><?php echo $content; ?></div> 
</div> 
+0

查看页面源 - 是HTML正确 – 2016-07-08 04:01:53

+0

你得到的代码检查?? PS任何错误代码:你的代码可以通过SQL注入 –

+0

注射后' <?php' add'error_reporting(E_ALL); ini_set('display_errors' ,1);'并写入'$ sql = mysqli_query($ con,“SELECT * FROM collage WHERE id ='$ id'”)或死(mysqli_error($ con));'并检查错误 –

回答

1

这里的问题是“你所有的变量都是本地的while循环”。所以你不能在while循环之外访问它。试试这个代码。

<?php 
     include('config/dbconnect.php'); 
     if(isset($_GET['id'])) 
     { 
      $id = $_GET['id']; 
      $sql = mysqli_query($con, "SELECT * FROM collage WHERE id = '$id'"); 
      while($row = mysqli_fetch_array($sql)) { 
     ?> 

        <div class='body-content'> 
        <div class='img-name-cont'><h3><?php echo $row['name']; ?></h3></div> 
        <div class='img-detail-cont'>upload: <?php echo $row['date_upload']; ?><br>type: 
        <?php echo $row['type']; ?><br>size: <?php echo $row['size']; ?>KB </div> 
        <div class='img-file-cont'> 
        <img src="img/collage/<?php echo $row['file']; ?>" style="width:130px; height:100%"></div> 
        <div class='img-content-cont'><?php echo $row['content']; ?></div> 
        </div> 
     <?php 
      } 
     } 
?> 
+0

谢谢你dulaj ..我会试试这个。 – Ryan

0

嘿通过Dulaj嘉亚的回答您的所有variableslocal所以你不能使用的while那外面。其次,如果你想用你的代码,那么你已经采取的$row所有的数据在不同的variables则使用的文件之外,那么为什么,为什么你已经使用$row['file'];

只需更换这条线

你不使用相同的 $fileimage
<div class='img-file-cont'> 
        <img src="img/collage/<?php echo $file; ?>" style="width:130px; height:100%"></div> 
+0

谢谢你mamta – Ryan

2

首先使用检查来检查图像是否实际上是由代码指向的。那实际的兴趣可能没有指向。什么是你的文件夹结构。

“style =”width:130px;身高:100%“>

你的代码是好的,只要PHP的echo $行[‘文件’]返回一个文件

0

一定要检查echo $row['file']如果返回的图像路径的正确的字符串。 ?用正确的文件扩展名

+0

谢谢你的优雅。 – Ryan

0

 
try this one :

first of all you have to check if your image path ok or not using this php function:

<?php $img=getimagesize($imagewithpath); if($img=="") { echo "there is no image ";} else{ ?> <img src="<?php echo $imagewithpath; ?>" style="width:130px; height:100%"> <?php } ?>
+0

谢谢你的建议Ashish。 – Ryan