public function downloadAction() { $aid = (int) $this->getInput('aid', 'get'); $submit = (int) $this->getInput('submit', 'post'); $attach = Wekit::load('attach.PwThreadAttach')->getAttach($aid); if (!$attach) { $this->showError('BBS:thread.buy.attach.error'); } Wind::import('SRV:forum.bo.PwForumBo'); $forum = new PwForumBo($attach['fid']); if (!$forum->isForum()) { $this->showError('data.error'); } if ($attach['cost'] && !$this->loginUser->isExists()) { $this->showError('download.fail.login.not', 'bbs/attach/download'); } if (!$forum->allowDownload($this->loginUser)) { if (!$this->loginUser->isExists()) { $this->showError('download.fail.login.not', 'bbs/attach/download'); } $this->showError(array('BBS:forum.permissions.download.allow', array('{grouptitle}' => $this->loginUser->getGroupInfo('name')))); } if (!$forum->foruminfo['allow_download'] && !$this->loginUser->getPermission('allow_download')) { if (!$this->loginUser->isExists()) { $this->showError('download.fail.login.not', 'bbs/attach/download'); } $this->showError(array('permission.download.allow', array('{grouptitle}' => $this->loginUser->getGroupInfo('name')))); } Wind::import('SRV:credit.bo.PwCreditBo'); $creditBo = PwCreditBo::getInstance(); // 购买积分检查 if (($attach = $this->_checkAttachCost($attach)) instanceof PwError) { $this->showError($attach->getError()); } // 下载积分检查 if (($reduceDownload = $this->_checkAttachDownload('download_att', $attach, $forum)) instanceof PwError) { $this->showError($reduceDownload->getError()); } //下载积分提示 $lang = Wind::getComponent('i18n'); if (1 == $this->loginUser->getPermission('allow_download') && $reduceDownload && $attach['cost']) { $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.all', array('{buyCount}' => -$attach['cost'] . $creditBo->cType[$attach['ctype']], '{downCount}' => rtrim($reduceDownload, ','))); } elseif (1 == $this->loginUser->getPermission('allow_download') && $reduceDownload && !$attach['cost']) { $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.download', array('{downCount}' => rtrim($reduceDownload, ','))); } elseif ($attach['cost']) { $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.buy', array('{count}' => $this->loginUser->getCredit($attach['ctype']) . $creditBo->cType[$attach['ctype']], '{buyCount}' => -$attach['cost'] . $creditBo->cType[$attach['ctype']])); } else { $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.success'); } !$submit && $this->showMessage($dataShow); //购买积分操作 $this->_operateBuyCredit($attach); // 下载积分 if ($reduceDownload) { Wind::import('SRV:attach.dm.PwThreadAttachBuyDm'); $dm = new PwThreadAttachBuyDm(); $dm->setAid($aid)->setCreatedUserid($this->loginUser->uid)->setCreatedTime(Pw::getTime())->setCtype($attach['ctype'])->setCost($attach['cost']); Wekit::load('attach.PwThreadAttachDownload')->add($dm); $this->_operateCredit('download_att', $forum); } //更新附件点击数 Wind::import('SRV:attach.dm.PwThreadAttachDm'); $dm = new PwThreadAttachDm($aid); $dm->addHits(1); Wekit::load('attach.PwThreadAttach')->updateAttach($dm); $filename = basename($attach['path']); $fileext = substr(strrchr($attach['path'], '.'), 1); $filesize = 0; if (strpos(Wind::getApp()->getRequest()->getServer('HTTP_USER_AGENT'), 'MSIE') !== false && $fileext == 'torrent') { $attachment = 'inline'; } else { $attachment = 'attachment'; } $attach['name'] = trim(str_replace(' ', ' ', $attach['name'])); if (strtoupper(Wekit::V('charset')) == 'UTF-8') { $attach['name'] = Pw::convert($attach['name'], "gbk", 'utf-8'); } $filesize = 0; $fgeturl = Wind::getComponent('storage')->getDownloadUrl($attach['path']); if (strpos($fgeturl, 'http') !== 0) { if (!is_readable($fgeturl)) { $this->showError('BBS:thread.buy.attach.error'); } $filesize = filesize($fgeturl); } $timestamp = Pw::getTime(); $ctype = ''; switch ($fileext) { case "pdf": $ctype = "application/pdf"; break; case "rar": case "zip": $ctype = "application/zip"; break; case "doc": $ctype = "application/msword"; break; case "xls": $ctype = "application/vnd.ms-excel"; break; case "ppt": $ctype = "application/vnd.ms-powerpoint"; break; case "gif": $ctype = "image/gif"; break; case "png": $ctype = "image/png"; break; case "jpeg": case "jpg": $ctype = "image/jpeg"; break; case "wav": $ctype = "audio/x-wav"; break; case "mpeg": case "mpg": case "mpe": $ctype = "video/x-mpeg"; break; case "mov": $ctype = "video/quicktime"; break; case "avi": $ctype = "video/x-msvideo"; break; case "txt": $ctype = "text/plain"; break; default: $ctype = "application/octet-stream"; } ob_end_clean(); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT'); header('Cache-control: max-age=86400'); header('Content-Encoding: none'); header("Content-Disposition: {$attachment}; filename=\"{$attach['name']}\""); header("Content-type: {$ctype}"); header("Content-Transfer-Encoding: binary"); $filesize && header("Content-Length: {$filesize}"); $i = 1; while (!@readfile($fgeturl)) { if (++$i > 3) { break; } } exit; }