to($attachment); if($this->request->filter('int')->cid) { Typecho_Db::get()->fetchRow(Typecho_Db::get()->select()->from('table.contents') ->where('table.contents.type = ?', 'attachment') ->where('table.contents.cid = ?', $this->request->filter('int')->cid) ->limit(1), array($this, 'push')); if (!$this->have()) { throw new \InvalidArgumentException("文件不存在"); } $info = unserialize($this->text); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: {$info['mime']}"); header("Content-Disposition: attachment; filename=\"{$info['name']}\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: {$info['size']}"); // download $file = @fopen($_SERVER['DOCUMENT_ROOT'].$info['path'],"rb"); if ($file) { while(!feof($file)) { print(fread($file, 1024*8)); flush(); if (connection_status()!=0) { @fclose($file); die(); } } @fclose($file); } } } }