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
我的问题出在我的代码上,我似乎无法弄清楚如何将<a>
标记内的php变量用作href=""
。下面是我的代码,
<?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>";
?>
以防万一,您想看一下我的上传代码,就在这里
<?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);
}
}
?>
答案 0 :(得分:0)
您只需要concat
echo "</td><td><a href='".$image."'>Download</a></td></tr>";