改名
This commit is contained in:
@@ -275,21 +275,32 @@ class Response extends HttpService
|
|||||||
* @param int $offset
|
* @param int $offset
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*/
|
*/
|
||||||
public function sendFile(string $path, $offset = 0, $limit = 1024000)
|
public function sendFile(string $path, $offset = 0, $limit = 1024000, $sleep = 0)
|
||||||
{
|
{
|
||||||
$open = fopen($path, 'r');
|
$open = fopen($path, 'r');
|
||||||
|
|
||||||
|
$name = explode(DIRECTORY_SEPARATOR, $path);
|
||||||
|
|
||||||
$stat = fstat($open);
|
$stat = fstat($open);
|
||||||
$this->response->setHeader('Content-Length', $stat['size']);
|
$this->response->setHeader('Content-Length', $stat['size']);
|
||||||
|
$this->response->setHeader('Content-Type', 'application/octet-stream');
|
||||||
|
$this->response->setHeader('Content-Disposition', ' attachment; filename="' . end($name) . '"');
|
||||||
|
$this->response->setHeader('Content-Transfer-Encoding', 'binary');
|
||||||
|
|
||||||
while ($file = fread($open, $limit)) {
|
while ($file = fread($open, $limit)) {
|
||||||
$this->response->write($file);
|
$this->response->write($file);
|
||||||
fseek($open, $offset);
|
fseek($open, $offset);
|
||||||
|
if ($sleep > 0) {
|
||||||
|
sleep($sleep);
|
||||||
|
}
|
||||||
if ($offset >= $stat['size']) {
|
if ($offset >= $stat['size']) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$offset += $limit;
|
$offset += $limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->response->end();
|
||||||
|
$this->response = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class Server extends HttpService
|
|||||||
|
|
||||||
Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION);
|
Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION);
|
||||||
|
|
||||||
// Coroutine::set(['enable_deadlock_check' => false]);
|
Coroutine::set(['enable_deadlock_check' => false]);
|
||||||
|
|
||||||
return $baseServer->start();
|
return $baseServer->start();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user