I have Uploaded files to a directory and in database and i want to show the files in the browser and make the downloadable but on one file is showing in the browser. How it shows one file in browser. Here is how the database looks like Database. Here is the Directory of my Files Image Directory And the code that i wrote
<?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>";
}
}
?>
How can i make the images horizontally styled i.e movies.txt followed by procurement.pdf etc. like this Procument file should be under movies.txt.
Define your table outside of the loop and inside the loop only the rows.
Example:
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;
}
Btw. Your code is vulnerable for SQL injections!
To show the files in one row (e.g. file1.txt, file2.txt ...) just move the
<tr><td></td></tr>
out of the loop and only append the links inside the loop.$output .= '<a href="' . $file['ReturnDir'] . '"> ' . $file['ReturnName'] . '</a> ';