温馨提示:本文翻译自stackoverflow.com,查看原文请点击:html - How to show all files from DB horizontaly using php?
crud html mysql php

html - 如何使用PHP显示来自DB Horizo​​ntaly的所有文件?

发布于 2020-04-17 13:36:45

我已将文件上载到目录和数据库中,我想在浏览器中显示文件并使其可下载,但浏览器中显示一个文件。如何在浏览器中显示一个文件这里是数据库的样子数据库这是我的文件图像目录的目录以及我编写的代码

<?php
     $Year = mysqli_query($link, "SELECT distinct `Year` FROM `returndocs` WHERE EmailAddress='$name'");
     $Returns = 'Returns';
     if($Year->num_rows>0)
         {
            while ($row=$Year->fetch_assoc())
                {
                   echo "<button type='button' class='collapsible'>
                           <div style='display:flex'>
                              <div><img src='../Assets/images/icons/folder-icon.png' width='18' height='18'></div>
                                <div style='margin-left:5px;'>".$row['Year'].' '.$Returns."</div>
                           </div>
                         </button>";
                }
          }
     else{
             echo "<h6 style='color:#bf9038;'>No returns Submitted!</h6>";
         }
// Viewing files from Db and from directory 
$SelectUploadedFiles = mysqli_query($link, "SELECT * FROM `returndocs` where EmailAddress='$name';");
if($SelectUploadedFiles->num_rows > 0)
   {
       while($file=$SelectUploadedFiles->fetch_assoc())
            {
               echo "<div class='content'>
                      <table>
                          <tr><a href=".$file['ReturnDir']." download>".$file['ReturnName']."</a></tr>
                      </table>
                  </div>";
             }
    }
?>

我该如何使图像水平样式化​​,例如,movies.txt,然后是purchase.pdf等,此类采购文件应位于movies.txt下

查看更多

提问者
sehphirrydev
被浏览
27
CodyKL 2020-02-04 18:19

在循环外和循环内仅定义行的表。

例:

if($SelectUploadedFiles->num_rows > 0) {
    // Define the div and table opening elements
    $ouput = '<div class="content"><table>';
    while($file=$SelectUploadedFiles->fetch_assoc()) {
        // Append for each entry a new table row
        $output .= '<tr><td><a href="' . $file['ReturnDir'] . '"> ' . $file['ReturnName'] . '</a></td></tr>';
    }
    // Close the table and div elements
    $output .= '</table></div>';
    // Show the table
    echo $output;
}

顺便说一句。您的代码容易受到SQL注入的攻击!