duanpen9294 2018-07-10 16:36
浏览 101
已采纳

将Echo的<a>标签用作PHP网站中的下载链接

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);
  }
 }
?>
  • 写回答

1条回答 默认 最新

  • dongwenhui8900 2018-07-10 16:40
    关注

    You just need concat

    echo "</td><td><a href='".$image."'>Download</a></td></tr>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改