| @@ -38,8 +38,13 @@ | ||
| 38 | 38 | */ |
| 39 | 39 | protected $storage; |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | + * @var | |
| 43 | + */ | |
| 44 | + protected $separator; | |
| 45 | + | |
| 46 | + /** | |
| 42 | 47 | * @param Config $config |
| 43 | 48 | * @param AuthInterface $auth |
| 44 | 49 | * @param Filesystem $storage |
| 45 | 50 | */ |
| @@ -51,8 +56,10 @@ | ||
| 51 | 56 | $this->user = $this->auth->user() ?: $this->auth->getGuest(); |
| 52 | 57 | |
| 53 | 58 | $this->storage = $storage; |
| 54 | 59 | $this->storage->setPathPrefix($this->user->getHomeDir()); |
| 60 | + | |
| 61 | + $this->separator = $this->storage->getSeparator(); | |
| 55 | 62 | } |
| 56 | 63 | |
| 57 | 64 | /** |
| 58 | 65 | * @param Request $request |
| @@ -74,9 +81,9 @@ | ||
| 74 | 81 | } catch (\Exception $e) { |
| 75 | 82 | return $response->redirect('/'); |
| 76 | 83 | } |
| 77 | 84 | |
| 78 | - $this->downloadFile($file, $request, $streamedResponse); | |
| 85 | + $this->downloadFile($file, $request, $response, $streamedResponse); | |
| 79 | 86 | } |
| 80 | 87 | |
| 81 | 88 | /** |
| 82 | 89 | * @param $file array |
| @@ -83,19 +90,24 @@ | ||
| 83 | 90 | * @param Request $request |
| 84 | 91 | * @param StreamedResponse $streamedResponse |
| 85 | 92 | * @return void |
| 86 | 93 | */ |
| 87 | - public function downloadFile(array $file, Request $request, StreamedResponse $streamedResponse) | |
| 94 | + public function downloadFile(array $file, Request $request, Response $response, StreamedResponse $streamedResponse) | |
| 88 | 95 | { |
| 89 | 96 | |
| 97 | + if($file['stream'] === false) { | |
| 98 | + return $response->json('Cannot read file, please check file permissions!', 422); | |
| 99 | + } | |
| 100 | + | |
| 90 | 101 | $streamedResponse->setCallback(function () use ($file) { |
| 91 | 102 | // @codeCoverageIgnoreStart |
| 92 | - set_time_limit(0); | |
| 103 | + @set_time_limit(0); | |
| 104 | + | |
| 93 | 105 | if ($file['stream']) { |
| 94 | 106 | while (! feof($file['stream'])) { |
| 95 | 107 | echo fread($file['stream'], 1024 * 8); |
| 96 | - ob_flush(); | |
| 97 | - flush(); | |
| 108 | + @ob_flush(); | |
| 109 | + @flush(); | |
| 98 | 110 | } |
| 99 | 111 | fclose($file['stream']); |
| 100 | 112 | } |
| 101 | 113 | // @codeCoverageIgnoreEnd |
| @@ -204,18 +216,20 @@ | ||
| 204 | 216 | { |
| 205 | 217 | |
| 206 | 218 | |
| 207 | 219 | $uniqid = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('uniqid')); |
| 220 | + $name = $request->input('name', $this->config->get('file.default_archive_name')); | |
| 221 | + | |
| 208 | 222 | $file = $tmpfs->readStream($uniqid); |
| 209 | 223 | |
| 210 | 224 | $streamedResponse->setCallback(function () use ($file, $tmpfs, $uniqid) { |
| 211 | 225 | // @codeCoverageIgnoreStart |
| 212 | - set_time_limit(0); | |
| 226 | + @set_time_limit(0); | |
| 213 | 227 | if ($file['stream']) { |
| 214 | 228 | while (! feof($file['stream'])) { |
| 215 | 229 | echo fread($file['stream'], 1024 * 8); |
| 216 | - ob_flush(); | |
| 217 | - flush(); | |
| 230 | + @ob_flush(); | |
| 231 | + @flush(); | |
| 218 | 232 | } |
| 219 | 233 | fclose($file['stream']); |
| 220 | 234 | } |
| 221 | 235 | $tmpfs->remove($uniqid); |
| @@ -225,10 +239,10 @@ | ||
| 225 | 239 | $streamedResponse->headers->set( |
| 226 | 240 | 'Content-Disposition', |
| 227 | 241 | HeaderUtils::makeDisposition( |
| 228 | 242 | HeaderUtils::DISPOSITION_ATTACHMENT, |
| 229 | - $this->config->get('file.default_archive_name'), | |
| 230 | - 'archive.zip' | |
| 243 | + $name, | |
| 244 | + $this->config->get('file.default_archive_name') | |
| 231 | 245 | ) |
| 232 | 246 | ); |
| 233 | 247 | $streamedResponse->headers->set( |
| 234 | 248 | 'Content-Type', |