This commit is contained in:
2021-09-07 16:14:44 +08:00
parent 968814bd57
commit e412f0681f
7 changed files with 144 additions and 84 deletions
+19
View File
@@ -7,6 +7,7 @@ use JetBrains\PhpStorm\Pure;
use Kiri\Core\Help;
use Kiri\ToArray;
use Psr\Http\Message\ResponseInterface;
use Server\SInterface\DownloadInterface;
/**
@@ -174,6 +175,24 @@ class Response implements ResponseInterface, \Server\ResponseInterface
}
/**
* @param $path
* @param bool $isChunk
* @param int $size
* @param int $offset
* @return DownloadInterface
* @throws Exception
*/
public function file($path, bool $isChunk = false, int $size = -1, int $offset = 0): DownloadInterface
{
$path = realpath($path);
if (!file_exists($path) || !is_readable($path)) {
throw new Exception('Cannot read file "' . $path . '", no permission');
}
return (new Download())->path($path, $isChunk, $size, $offset);
}
/**
* @param $responseData
* @return string|array|bool|int|null