PluginProbe
WPIDE – File Manager & Code Editor / 3.5.10
WPIDE – File Manager & Code Editor v3.5.10
3.5.10 3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 All 56 releases
← All changes | App/Controllers/FileManager/DownloadController.php +62 -10 3.2 → 3.5.10 View file →
@@ -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,11 +81,34 @@
74 81 } catch (\Exception $e) {
75 82 return $response->redirect('/');
76 83 }
77 84
78 - $this->downloadFile($file, $request, $streamedResponse);
85 + return $this->downloadFile($file, $request, $response, $streamedResponse);
79 86 }
80 87
88 + public function readContent(Request $request, Response $response)
89 + {
90 + $encodedPath = $request->input('path');
91 + $path = is_string($encodedPath) ? base64_decode($encodedPath, true) : false;
92 +
93 + if ($path === false || !$this->storage->fileExists($path)) {
94 + return $response->json(__('Requested file does not exist', 'wpide'), 404);
95 + }
96 +
97 + try {
98 + $file = $this->storage->read($path);
99 + } catch (\Exception $error) {
100 + return $response->json(__('Cannot read file, please check file permissions!', 'wpide'), 422);
101 + }
102 +
103 + $content = $file['contents'];
104 + if (!is_string($content) || strlen($content) !== (int) $file['filesize'] || preg_match('//u', $content) !== 1) {
105 + return $response->json(__('Cannot read file, please check file permissions!', 'wpide'), 422);
106 + }
107 +
108 + return $response->json($content);
109 + }
110 +
81 111 /**
82 112 * @param $file array
83 113 * @param Request $request
84 114 * @param StreamedResponse $streamedResponse
@@ -83,19 +113,39 @@
83 113 * @param Request $request
84 114 * @param StreamedResponse $streamedResponse
85 115 * @return void
86 116 */
87 - public function downloadFile(array $file, Request $request, StreamedResponse $streamedResponse)
117 + public function downloadFile(array $file, Request $request, Response $response, StreamedResponse $streamedResponse)
88 118 {
89 119
120 + if($file['stream'] === false) {
121 + return $response->json('Cannot read file, please check file permissions!', 422);
122 + }
123 +
124 + // Output produced before this response would be prepended to the file. With
125 + // Content-Length set below, clients can then lose the same number of bytes
126 + // from the end of the file.
127 + if (headers_sent()) {
128 + fclose($file['stream']);
129 + return $response->json('Cannot safely stream file!', 500);
130 + }
131 +
132 + while (ob_get_level() > 0) {
133 + if (!@ob_end_clean()) {
134 + fclose($file['stream']);
135 + return $response->json('Cannot safely stream file!', 500);
136 + }
137 + }
138 +
90 139 $streamedResponse->setCallback(function () use ($file) {
91 140 // @codeCoverageIgnoreStart
92 - set_time_limit(0);
141 + @set_time_limit(0);
142 +
93 143 if ($file['stream']) {
94 144 while (! feof($file['stream'])) {
95 145 echo fread($file['stream'], 1024 * 8);
96 - ob_flush();
97 - flush();
146 + @ob_flush();
147 + @flush();
98 148 }
99 149 fclose($file['stream']);
100 150 }
101 151 // @codeCoverageIgnoreEnd
@@ -204,18 +254,20 @@
204 254 {
205 255
206 256
207 257 $uniqid = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('uniqid'));
258 + $name = $request->input('name', $this->config->get('file.default_archive_name'));
259 +
208 260 $file = $tmpfs->readStream($uniqid);
209 261
210 262 $streamedResponse->setCallback(function () use ($file, $tmpfs, $uniqid) {
211 263 // @codeCoverageIgnoreStart
212 - set_time_limit(0);
264 + @set_time_limit(0);
213 265 if ($file['stream']) {
214 266 while (! feof($file['stream'])) {
215 267 echo fread($file['stream'], 1024 * 8);
216 - ob_flush();
217 - flush();
268 + @ob_flush();
269 + @flush();
218 270 }
219 271 fclose($file['stream']);
220 272 }
221 273 $tmpfs->remove($uniqid);
@@ -225,10 +277,10 @@
225 277 $streamedResponse->headers->set(
226 278 'Content-Disposition',
227 279 HeaderUtils::makeDisposition(
228 280 HeaderUtils::DISPOSITION_ATTACHMENT,
229 - $this->config->get('file.default_archive_name'),
230 - 'archive.zip'
281 + $name,
282 + $this->config->get('file.default_archive_name')
231 283 )
232 284 );
233 285 $streamedResponse->headers->set(
234 286 'Content-Type',