protected function postFilter() { parent::postFilter(); if (isset($this->file)) { $elem = \ManiaLib\Gui\Maniacode\Maniacode::$domDocument->createElement('file'); $value = \ManiaLib\Gui\Maniacode\Maniacode::$domDocument->createTextNode($this->file); $elem->appendChild($value); $this->xml->appendChild($elem); } }
public function down() { set_time_limit(2 * 3600); $urlkey = $_REQUEST['urlkey']; if (!$urlkey) { $mapId = (int) $_REQUEST['id']; if (!$mapId) { echo Response::json(LACK, array(tip('参数不全'))); exit; } } else { $mapId = base_convert($urlkey, 36, 10); } $fac = Factory::getInstance(); $info = $fac->getFileMap($mapId); if (!$info['location']) { include VIEW_PATH . 'error.php'; exit; } // if ($_SESSION['CLOUD_UID'] != $info['uid']) { $pids = str_replace('/', ',', trim($info['path'], '/')); $ids = ($pids ? $pids . ',' : '') . $mapId; $shares = $fac->getShareByMap($ids); if ($shares) { $keys = array(); foreach ($shares as $v) { $keys[$v['mapId']] = $v['mapId']; $shares[$v['mapId']] = $v; } $shareInfo = $shares[max($keys)]; } else { include VIEW_PATH . 'error.php'; exit; } if ($shareInfo) { if (strtotime($shareInfo['overTime']) < time() && $shareInfo['overTime'] != '0000-00-00 00:00:00') { include VIEW_PATH . 'error.php'; exit; } $fac->incrShareDown($shareInfo['id']); if ($info['isdir'] || $shareInfo['pwd'] && !$_SESSION['share'][self::getClientIp() . ':' . $shareInfo['mapId']]) { include VIEW_PATH . 'error.php'; exit; } } else { include VIEW_PATH . 'error.php'; exit; } } // $url = parse_url(trim($info['name'], '/')); $pathArray = explode('/', $url['path']); $fileName = end($pathArray); if (!$fileName) { $fileName = 'sorry.' . pathinfo($url['path'], PATHINFO_EXTENSION); } $fsize = (int) $info['size']; if ($info['location']) { header('Content-type: ' . ($info['mime'] ? $info['mime'] : 'application/octet-stream')); if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) { header('Content-Disposition: attachment; filename="' . rawurlencode($fileName) . '"'); } else { if (preg_match("/Firefox/", $_SERVER["HTTP_USER_AGENT"])) { header('Content-Disposition: attachment; filename*="utf8\'\'' . $fileName . '"'); } else { header('Content-Disposition: attachment; filename="' . $fileName . '"'); } } session_write_close(); if (!extension_loaded('fastdfs_client')) { header('cache-control:public'); include LIB_PATH . 'down' . DS . 'FileDownload.class.php'; $obj = new FileDownload(); $obj->download($info['location'], $fileName, $fsize, true); } else { $group = (include FDFS . 'group.php'); $g = strtok($info['location'], '/'); $ips = $group[$g]; if ($ips) { shuffle($ips); echo file_get_contents('http://' . $ips[0] . '/' . $info['location']); } else { include VIEW_PATH . 'error.php'; } } } else { header("HTTP/1.1 404 Not Found"); header('Content-Type: text/html; charset=utf-8'); } }
function __construct($name = '', $url = '') { parent::__construct($name, $url); }
/** * output file to download * * @param string path to file to download * @param string * @param bool */ protected function downloadFile($srcFile, $publicFilename = null, $deleteAfterDownload = false) { if (empty($publicFilename)) { $publicFilename = basename($srcFile); } $filedownload = new FileDownload(); $filedownload->sourceFile = $srcFile; $filedownload->transferFileName = $publicFilename; if ($deleteAfterDownload) { $filedownload->onComplete[] = function (FileDownload $download, IDownloader $downloader) use($srcFile) { unlink($srcFile); }; } $filedownload->download(); exit(0); }
} $range = array_combine(array('start', 'end'), $range); if (empty($range['start'])) { $range['start'] = 0; } if (empty($range['end'])) { $range['end'] = $file_size; } return $range; } return null; } } $file = 'book.zip'; $name = time() . '.zip'; $obj = new FileDownload(); $flag = $obj->download($file, $name); //$flag = $obj->download($file, $name, true); // 断点续传 if (!$flag) { echo 'file not exists'; } /* fdipzone@ubuntu:~/Downloads$ wget -O test.rar http://demo.fdipzone.com/demo.php --2013-06-30 16:52:44-- http://demo.fdipzone.com/demo.php 正在解析主机 demo.fdipzone.com... 127.0.0.1 正在连接 demo.fdipzone.com|127.0.0.1|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度: 10445120 (10.0M) [application/octet-stream] 正在保存至: “test.rar” 30% [============================> ] 3,146,580 513K/s 估时 14s ^C
/** * @param string $file filename */ public function handleDownload($file) { $fd = new FileDownload(); $fd->sourceFile = $this->path . 'backups/' . $file; $fd->onBeforeDownloaderStarts[] = function ($fd) { header('Content-Length: ' . $fd->sourceFileSize); }; $fd->download(); }