我已将文件上载到目录和数据库中,我想在浏览器中显示文件并使其可下载,但浏览器中显示一个文件。如何在浏览器中显示一个文件。这里是数据库的样子数据库。这是我的文件图像目录的目录以及我编写的代码
<?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下。
在循环外和循环内仅定义行的表。
例:
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注入的攻击!
要在一行中显示文件(例如file1.txt,file2.txt ...),只需将其
<tr><td></td></tr>
移出循环,而仅将链接附加到循环内即可。$output .= '<a href="' . $file['ReturnDir'] . '"> ' . $file['ReturnName'] . '</a> ';