zoukankan      html  css  js  c++  java
  • TP框架下载功能 - 不想下天桥 - 博客园

    复制代码
    namespace HomeController;
    use ThinkController;
    use OrgNetHttp;
    class IndexController extends Controller {
    
        public function download(){
          //获取文件的唯一id(这里可以将展示页面的对应表的id保存在session里,然后使用download方法获取该id) $file_id = session('id'); if( $file_id == 0 ){ $this -> error( '文件不存在' ); } $db_file = M( '表名' );
           //匿名组合数据 $condition [ 'file_id' ] = $file_id;
           //通过上面条件查找数据表文件路径 $file_result = $db_file -> where( $condition )->field('file_path') -> find( ); if( empty( $file_result ) || ! file_exists( $file_result[ 'file_path' ] ) ){ $this -> error( '文件不存在' ); }
           //如果文件路径是由多个东西组合而成(如时间戳,保存文件地址等),需要截取出文件名 $showname = $file_result[ 'show_name' ]; $ext_arr = explode( '.' , $file_path ); $showname .= '.'.$ext_arr[ count( $ext_arr ) -1 ]; $encoded_filename = urlencode( $showname ); $encoded_filename = str_replace( "+" , " " , $encoded_filename ); Http::download( $file_result[ 'file_path' ] , $showname ); } }
  • 相关阅读:
    3.09课·········打印矩形,三角形和菱形
    3.09课·········for穷举和迭代
    3.09课·········for循环
    Django的中间件
    Cookie和Session
    Django之ORM
    Django ORM那些相关操作
    Django form表单
    Django model 中的 class Meta 详解
    pymysql模块的使用
  • 原文地址:https://www.cnblogs.com/lxwphp/p/7731328.html
Copyright © 2011-2022 走看看