So, I have a simple upload/download form on my PHP website. I have it set so that the files get uploaded to my upload folder within my IIS website. I want to have a link to download the file next to the table as such,
Desired Output
My problem is with my code and I can't seem to figure out how to use the php variable inside the <a>
tag as the href=""
. Below is my code,
<?php
//path to directory to scan
$directory = "uploads/";
//get all image files with a .jpg extension.
$images = glob($directory . "*.*");
echo "<div class='col-md-12' align='center'><div class='col-sm-8'>
<table class='table table-bordered table-striped'>
<tr>
<th width='80%'>Filename</th>
<th width='20%'>Download</th>
</tr>";
//print each file name
foreach($images as $image)
{
echo "<tr><td>";
echo $image;
/*<a href="http://www.whatever.com/<?php echo $param; ?>">Click
Here</a>*/
echo "</td><td><a href='<?php echo $image; ?>'>Download</a></td>
</tr>";
}
echo "</table></div></div>";
?>
And just in case you would like to see my upload code, here it is
<?php
if(isset($_FILES['file'])){
$errors= array();
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_tmp =$_FILES['file']['tmp_name'];
$file_type=$_FILES['file']['type'];
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"uploads\\".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
?>