コード例 #1
0
ファイル: LogService.php プロジェクト: lawguangwei/webDB
 public function disabledFiles($page)
 {
     $conn = Yii::$app->db;
     $sql = 'select count(*) as counts from file_manage_log';
     $command = $conn->createCommand($sql);
     $result = $command->queryOne();
     $pages = floor($result['counts'] / 20) + 1;
     $sql = 'select * from file_manage_log order by create_date desc limit ' . $page * (20 - 1) . ',20';
     $command = $conn->createCommand($sql);
     $files = $command->queryAll();
     for ($i = 0; $i < count($files); $i++) {
         $file = UserFile::findOne($files[$i]['file_id']);
         $files[$i]['file_type'] = $file->filetype;
         $files[$i]['file_size'] = round($file->filesize / (1024 * 1024), 2);
         $admin = Admin::findOne(['admin_id' => $files[$i]['admin_id']]);
         $files[$i]['admin'] = $admin->admin_account;
     }
     $conn->close();
     $data['pages'] = $pages;
     $data['page'] = $page;
     $data['files'] = $files;
     return $data;
 }
コード例 #2
0
ファイル: FileService.php プロジェクト: lawguangwei/webDB
 public function countFileSize()
 {
     $result = UserFile::find()->all();
     $sum = 0;
     foreach ($result as $file) {
         $sum += $file['filesize'];
     }
     return $sum;
 }
コード例 #3
0
ファイル: AdminController.php プロジェクト: lawguangwei/webDB
 public function actionGetfile()
 {
     if (Yii::$app->request->isGet) {
         $file_id = $_GET['file_id'];
         $file = UserFile::findOne($file_id);
         Header("Content-type: " . $file->filetype);
         Header("Accept-Ranges: bytes");
         Header("Accept-Length: " . $file->length);
         Header("Content-Disposition: attachment; filename=" . $file->filename);
         /*
                     Header("Content-Disposition:  attachment;  filename=".$model->filename);
                     header("Content-Transfer-Encoding:binary");
                     header('Content-Length:'.$model->filesize);
                     header('Content-type:'.$model->filetype);
                     header('Expires:0');
                     header('Content-Type:application-x/force-download');*/
         $fp = $file->file->getResource();
         fseek($fp, 0);
         while (!feof($fp)) {
             set_time_limit(0);
             echo fread($fp, 1024);
             flush();
             ob_flush();
         }
         fclose($fp);
     }
 }