Php 显示动态创建的路径中的图像

Php 显示动态创建的路径中的图像,php,mysql,image,Php,Mysql,Image,我将多个图像保存到动态创建的数据库路径中。但现在的问题是,图像在抓取时没有显示。我在数据库中添加了两个表,以及输入图像时创建的php代码和目录。我想我的问题是图像源。我无法修改图像源路径。请帮忙 我在数据库中有两个表:第一个表:advt 表2:全文 这是我的php代码,用于显示数据库路径中的图像: <?php include('include/config.php'); if($stmt2 = $connection->prepare("SELECT img_id, ad_na

我将多个图像保存到动态创建的数据库路径中。但现在的问题是,图像在抓取时没有显示。我在数据库中添加了两个表,以及输入图像时创建的php代码和目录。我想我的问题是图像源。我无法修改图像源路径。请帮忙

我在数据库中有两个表:第一个表:advt

表2:全文

这是我的php代码,用于显示数据库路径中的图像:

<?php 
include('include/config.php');

 if($stmt2 = $connection->prepare("SELECT img_id, ad_name, img_name, img_type, img_size FROM `full texts`")){ 

       $stmt2->execute(); 
       $stmt2->store_result(); 
       $stmt2->bind_result($img_id, $ad_name, $img_name, $img_type, $img_size); 
       while($stmt2->fetch()){ 
         ?>
           <img src="'ad/data/img/'.$cus_id.'/'.$ad_id.'/'<?php echo $img_name; ?>" width="220" height="220"><br>

         <?php
       } 
       $stmt2->close();
    } 
?>

我认为php代码中的错误是因为在外部使用了php变量

更正代码:


如果您粘贴了浏览器得到的html代码,这将非常有用。 但您将php和普通html混合在一起,并迷失在其中,它应该是: 回声

否?>在该块和否之前,请尝试以下操作:

<?php 
    include('include/config.php');

    if($stmt = $connection->prepare("SELECT 
                                     a.img_id, 
                                     a.ad_name, 
                                     a.img_name, 
                                     a.img_type, 
                                     a.img_size, 
                                     b.ad_id, 
                                     b.cus_id 
                                     FROM `full texts` a 
                                     INNER JOIN advt b
                                     ON a.ad_name=b.ad_name
                                     ")){ 


           $stmt->execute(); 
           $stmt->store_result(); 
           $stmt->bind_result($img_id, $ad_name, $img_name, $img_type, $img_size, $ad_id, $cus_id);   

           while($stmt->fetch()){ 

              echo  "<img src=ad/data/img/$cus_id/$ad_id/$img_name  width='220' height='220'><br>";


           } 
           $stmt->close();
           } 

?>

为什么要将img_名称存储为blob?您可以简单地使用varchar并将图像名称保存在那里,如abc.jpg,并参考此处width=220 height=220>@Bikesh M Annur我根据您的建议将img_名称更改为varchar。但到目前为止,图像还没有显示。我建议您验证是否安装了AdBlocker,然后关闭它们进行再次测试。我只想从数据库中获取图像。现在没有过去的页面了。这就是为什么我在上传图像时添加了目录。现在的问题是:注意:未定义变量:第10行C:\xampp\htdocs\root\nfs\imageShow.php中的cus_id注意:第10PHP行C:\xampp\htdocs\root\nfs\imageShow.php中的未定义变量:ad_id正确-cus_id中存储了什么?你不能从数据库中得到它。您只接受$img\u id、$ad\u name、$img\u name、$img\u type、$img\u size,但不接受$cus\u id,这是您在构建路径时使用的。ad\u id、cus\u id都来自第一个表advt。cus_id是customer idies,但您没有选择它-这些不在SELECT中,因此PHP无法使用该值初始化变量-它是在您使用它创建路径时初始化的,但它是空的。现在的问题是:注意:未定义变量:第10行C:\xampp\htdocs\root\nfs\imageShow.php中的cus_id注意:第10行C:\xampp\htdocs\root\nfs\imageShow.php中的未定义变量:第10行C:\xampp\htdocs\root\nfs\imageShow.php中的cus_id注意:未定义变量:第10行C:\xampp\htdocs\root\nfs\imageShow.php中的ad_id是因为您没有从第一个表中提取ad_id&cus_如果您是从表1中提取的,则仅从表2中提取。如何使用准备好的语句plz指南将第一个表与第二个表连接在一起。在select语句和fetch记录中使用where条件。我没有更新,因为我没有更新有完整的代码
<?php 
include('include/config.php');

 if($stmt2 = $connection->prepare("SELECT img_id, ad_name, img_name, img_type, img_size FROM `full texts`")){ 

       $stmt2->execute(); 
       $stmt2->store_result(); 
       $stmt2->bind_result($img_id, $ad_name, $img_name, $img_type, $img_size); 
       while($stmt2->fetch()){ 
         ?>
           <img src="'ad/data/img/'.$cus_id.'/'.$ad_id.'/'<?php echo $img_name; ?>" width="220" height="220"><br>

         <?php
       } 
       $stmt2->close();
    } 
?>
$cus_id = $_POST['cus_id'];
$ad_id = $_POST['ad_id'];
$dir='ad/data/img/'.$cus_id.'/'.$ad_id.'/';
if(!file_exists($dir) || !is_dir($dir)){
    mkdir($dir, 0777, true);
    chmod($dir, 0777, true);
}
    <?php 
include('include/config.php');

 if($stmt2 = $connection->prepare("SELECT img_id, ad_name, img_name, img_type, img_size FROM `full texts`")){ 

       $stmt2->execute(); 
       $stmt2->store_result(); 
       $stmt2->bind_result($img_id, $ad_name, $img_name, $img_type, $img_size); 
       while($stmt2->fetch()){ 

          echo  "<img src=ad/data/img/$cus_id/$ad_id/$img_name  width="220" height='220'><br>";


       } 
       $stmt2->close();
    } 
?>
$stmt3 = $connection->prepare("SELECT ad_id, cus_id, ad_name, ad_des, date FROM `advt`" //where condition to particular img_id)
       $stmt3->execute(); 
           $stmt3->store_result(); 
           $stmt3->bind_result($ad_id, $cus_id, $ad_name, $ad_des, $date); 
while($stmt2->fetch()){ 

    $src = 'ad/data/img/'.$cus_id.'/'.$ad_id.'/'.$img_name;
     ?>
       <img src="<?php echo $src; ?>" width="220" height="220"><br>

     <?php
   }
<?php 
    include('include/config.php');

    if($stmt = $connection->prepare("SELECT 
                                     a.img_id, 
                                     a.ad_name, 
                                     a.img_name, 
                                     a.img_type, 
                                     a.img_size, 
                                     b.ad_id, 
                                     b.cus_id 
                                     FROM `full texts` a 
                                     INNER JOIN advt b
                                     ON a.ad_name=b.ad_name
                                     ")){ 


           $stmt->execute(); 
           $stmt->store_result(); 
           $stmt->bind_result($img_id, $ad_name, $img_name, $img_type, $img_size, $ad_id, $cus_id);   

           while($stmt->fetch()){ 

              echo  "<img src=ad/data/img/$cus_id/$ad_id/$img_name  width='220' height='220'><br>";


           } 
           $stmt->close();
           } 

?>