dongmi1872 2013-03-02 18:34
浏览 21

想要建立像下载这样的链接吗?id = **

I wanted to make download links in php.

For an example If i have 2 files in my directory then How do i make the download links like download.php?id=1 or 2 or anything.

So what will be the codes in the download.php file.

Please somebody tell me the codes.

  • 写回答

3条回答 默认 最新

  • dongxing1960 2013-03-02 18:39
    关注

    use $_GET

    example:

    <a href="download?id=1">link</a>
    
    <?php
    
    $id=$_GET['id'];
    
    if(is_numeric($id)){
    $filename = 'file.pdf'; // of course find the exact filename....        
    header( 'Pragma: public' ); // required
    header( 'Expires: 0' );
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
    header( 'Cache-Control: private', false ); // required for certain browsers 
    header( 'Content-Type: application/octet-stream' );
    
    header( 'Content-Disposition: attachment; filename="'. basename($filename) . '";' );
    header( 'Content-Transfer-Encoding: binary' );
    header( 'Content-Length: ' . filesize( $filename ) );
    
    readfile( $filename );
    
    exit;
    
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线