public function down()
 {
     $aid = I('get.attach_id');
     $attach = D('Attach/Attach')->find($aid);
     if (!$attach) {
         die(L('PUBLIC_ATTACH_ISNULL'));
     }
     $filename = $attach['filepath'] . $attach['savename'];
     $realname = auto_charset($attach['name'], 'UTF-8', 'GBK//IGNORE');
     if (file_exists($filename)) {
         Http::download($filename, $realname);
     } else {
         die(L('PUBLIC_ATTACH_ISNULL'));
     }
 }
Example #2
0
 public function downloadAllHomework()
 {
     $homeworkId = I('get.homeworkId');
     $courseId = I('get.courseId');
     if (empty($homeworkId) || empty($courseId)) {
         $this->error('参数错误');
     }
     $zipObject = new \ZipArchive();
     $homeworkDir = "./Uploads/Course/{$courseId}/homework/{$homeworkId}/";
     if ($handle = opendir($homeworkDir)) {
         $allHomework = "{$homeworkDir}course{$courseId}{$homewokrId}.zip";
         $zipObject->open($allHomework, $zipObject::CREATE);
         /* 这是正确地遍历目录方法 */
         while (false !== ($file = readdir($handle))) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $zipObject->addFile("{$homeworkDir}{$file}", "{$file}");
         }
         closedir($handle);
         \Org\Net\Http::download($allHomework);
     }
 }
 /**
  * 测试功能:测试http类的下载功能
  */
 public function testDownload()
 {
     Http::download("Image/ggk.png", "图片");
 }
 public function download()
 {
     if (I('get.file')) {
         $filename = base64_decode(I('get.file'));
         $file = C('BACKUP_PATH') . $filename;
         $res = \Org\Net\Http::download($file);
         if ($res) {
             $this->error($res);
         }
     } else {
         $this->error(L('_ERROR_ACTION_'));
     }
 }