Subversion-Projekte lars-tiefland.ci

Revision

Revision 2128 | Revision 2131 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2128 Revision 2130
Zeile 9... Zeile 9...
9
*
9
*
10
* Licensed under the MIT license:
10
* Licensed under the MIT license:
11
* https://opensource.org/licenses/MIT
11
* https://opensource.org/licenses/MIT
12
*/
12
*/
Zeile 13... Zeile 13...
13
 
13
 
14
if (preg_match("/\.local$/", $_SERVER["SERVER_NAME"]))
-
 
15
{
14
if (preg_match("/\.local$/", $_SERVER["SERVER_NAME"])) {
16
	//$GLOBALS["site"] .= ".local";
15
	//$GLOBALS["site"] .= ".local";
17
}
16
}
Zeile 18... Zeile 17...
18
$options = null;
17
$options = null;
19
 
18
 
20
$real_url = getDokDomain();
19
$real_url = getDokDomain();
Zeile 21... Zeile 20...
21
$real_url .= "/images/upload/";
20
$real_url .= "/images/upload/";
22
$real_folder = $GLOBALS["webs"]["verzeichnis"] . "/images/upload/";
21
$real_folder = $GLOBALS["webs"]["verzeichnis"] . "/images/upload/";
23
 
22
 
24
$folder = "";
-
 
25
$GLOBALS["folder"] = "";
23
$folder = "";
26
if (isset($_POST["folder"]) && $_POST["folder"])
24
$GLOBALS["folder"] = "";
27
{
-
 
28
	$folder = Weban_Utils::clean_global_input("folder");
25
if (isset($_POST["folder"]) && $_POST["folder"]) {
29
} elseif (isset($_GET["folder"]) && $_GET["folder"])
26
	$folder = Weban_Utils::clean_global_input("folder");
Zeile 30... Zeile 27...
30
{
27
} elseif (isset($_GET["folder"]) && $_GET["folder"]) {
31
	$folder = Weban_Utils::clean_global_input("folder", "get");
28
	$folder = Weban_Utils::clean_global_input("folder", "get");
32
}
-
 
33
 
29
}
34
$bvKonf = "";
30
 
35
if (isset($GLOBALS["web_rechte"]["admin"]["toolbox"]["bildverwaltung"]))
31
$bvKonf = "";
36
{
-
 
37
	$bvKonf = $GLOBALS["web_rechte"]["admin"]["toolbox"]["bildverwaltung"];
32
if (isset($GLOBALS["web_rechte"]["admin"]["toolbox"]["bildverwaltung"])) {
38
}
33
	$bvKonf = $GLOBALS["web_rechte"]["admin"]["toolbox"]["bildverwaltung"];
39
if (!$bvKonf)
34
}
40
{
35
if (!$bvKonf) {
41
	$bvKonf = "Bild;;651;651";
-
 
42
}
36
	$bvKonf = "Bild;;651;651";
43
$GLOBALS["Imagedaten"] = array_chunk(explode(";", $bvKonf), 4);
37
}
44
if ($folder)
38
$GLOBALS["Imagedaten"] = array_chunk(explode(";", $bvKonf), 4);
45
{
39
if ($folder) {
46
	$folder = rtrim($folder, "/");
40
	$folder = rtrim($folder, "/");
47
	$GLOBALS["folder"] = $folder;
41
	$GLOBALS["folder"] = $folder;
48
	$folder .= "/";
42
	$folder .= "/";
49
	$real_folder .= $folder;
43
	$real_folder .= $folder;
50
	$real_url .= $folder;
-
 
51
	$options["upload_dir"] = $real_folder;
44
	$real_url .= $folder;
52
	$options["upload_url"] = $real_url;
45
	$options["upload_dir"] = $real_folder;
53
	foreach ($GLOBALS["Imagedaten"] as $set)
46
	$options["upload_url"] = $real_url;
54
	{
47
	foreach ($GLOBALS["Imagedaten"] as $set) {
55
		$options["image_versions"][$set[0]] = array(
48
		$options["image_versions"][$set[0]] = array(
56
			"upload_dir" => $real_folder . $set[1] . "/",
49
			"upload_dir" => $real_folder . $set[1] . "/",
57
			"upload_url" => $real_url . $set[1] . "/",
50
			"upload_url" => $real_url . $set[1] . "/",
58
			"max_width" => $set[2],
51
			"max_width" => $set[2],
59
			"max_height" => $set[3],
-
 
60
			);
52
			"max_height" => $set[3],
61
	}
53
			);
62
	if (!file_exists($options["upload_dir"] . "/orig/"))
54
	}
Zeile 63... Zeile 55...
63
	{
55
	if (!file_exists($options["upload_dir"] . "/orig/")) {
Zeile 119... Zeile 111...
119
				'HEAD',
111
				'HEAD',
120
				'GET',
112
				'GET',
121
				'POST',
113
				'POST',
122
				'PUT',
114
				'PUT',
123
				'PATCH',
115
				'PATCH',
124
				'DELETE'),
116
				'DELETE',
-
 
117
				),
125
			'access_control_allow_headers' => array(
118
			'access_control_allow_headers' => array(
126
				'Content-Type',
119
				'Content-Type',
127
				'Content-Range',
120
				'Content-Range',
128
				'Content-Disposition'),
121
				'Content-Disposition',
-
 
122
				),
129
			// By default, allow redirects to the referer protocol+host:
123
			// By default, allow redirects to the referer protocol+host:
130
			'redirect_allow_target' => '/^' . preg_quote(parse_url($this->get_server_var('HTTP_REFERER'),
124
			'redirect_allow_target' => '/^' . preg_quote(parse_url($this->get_server_var('HTTP_REFERER'),
131
				PHP_URL_SCHEME) . '://' . parse_url($this->get_server_var('HTTP_REFERER'),
125
				PHP_URL_SCHEME) . '://' . parse_url($this->get_server_var('HTTP_REFERER'),
132
				PHP_URL_HOST) . '/', // Trailing slash to not match subdomains by mistake
126
				PHP_URL_HOST) . '/', // Trailing slash to not match subdomains by mistake
133
				'/' // preg_quote delimiter param
127
				'/' // preg_quote delimiter param
Zeile 141... Zeile 135...
141
			'download_via_php' => false,
135
			'download_via_php' => false,
142
			// Read files in chunks to avoid memory limits when download_via_php
136
			// Read files in chunks to avoid memory limits when download_via_php
143
			// is enabled, set to 0 to disable chunked reading of files:
137
			// is enabled, set to 0 to disable chunked reading of files:
144
			'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB
138
			'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB
145
			// Defines which files can be displayed inline when downloaded:
139
			// Defines which files can be displayed inline when downloaded:
146
			'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
140
			'inline_file_types' => '/\.(gif|jpe?g|png|svg)$/i',
147
			// Defines which files (based on their names) are accepted for upload:
141
			// Defines which files (based on their names) are accepted for upload:
148
			'accept_file_types' => '/.+$/i',
142
			'accept_file_types' => '/.+$/i',
149
			// The php.ini settings upload_max_filesize and post_max_size
143
			// The php.ini settings upload_max_filesize and post_max_size
150
			// take precedence over the following max_file_size setting:
144
			// take precedence over the following max_file_size setting:
151
			'max_file_size' => null,
145
			'max_file_size' => null,
Zeile 184... Zeile 178...
184
			'convert_params' => '-limit memory 32MiB -limit map 32MiB',
178
			'convert_params' => '-limit memory 32MiB -limit map 32MiB',
185
			*/
179
			*/
186
			// Command or path for to the ImageMagick identify binary:
180
			// Command or path for to the ImageMagick identify binary:
187
			'identify_bin' => 'identify',
181
			'identify_bin' => 'identify',
188
			'print_response' => true);
182
			'print_response' => true);
189
		foreach ($GLOBALS["Imagedaten"] as $set)
183
		foreach ($GLOBALS["Imagedaten"] as $set) {
190
		{
-
 
191
			$this->options["image_versions"][$set[0]] = array(
184
			$this->options["image_versions"][$set[0]] = array(
192
				"upload_dir" => $real_folder . $set[1] . "/",
185
				"upload_dir" => $real_folder . $set[1] . "/",
193
				"upload_url" => $real_url . $set[1] . "/",
186
				"upload_url" => $real_url . $set[1] . "/",
194
				"max_width" => $set[2],
187
				"max_width" => $set[2],
195
				"max_height" => $set[3],
188
				"max_height" => $set[3],
196
				);
189
				);
197
		}
190
		}
198
		if ($options)
191
		if ($options) {
199
		{
-
 
200
			$this->options = $options + $this->options;
192
			$this->options = $options + $this->options;
201
		}
193
		}
202
		if ($error_messages)
194
		if ($error_messages) {
203
		{
-
 
204
			$this->error_messages = $error_messages + $this->error_messages;
195
			$this->error_messages = $error_messages + $this->error_messages;
205
		}
196
		}
206
		if ($initialize)
197
		if ($initialize) {
207
		{
-
 
208
			$this->initialize();
198
			$this->initialize();
209
		}
199
		}
210
	}
200
	}
Zeile 211... Zeile 201...
211
 
201
 
212
	protected function initialize()
202
	protected function initialize()
213
	{
203
	{
214
		switch ($this->get_server_var('REQUEST_METHOD'))
-
 
215
		{
204
		switch ($this->get_server_var('REQUEST_METHOD')) {
216
			case 'OPTIONS':
205
			case 'OPTIONS':
217
			case 'HEAD':
206
			case 'HEAD':
218
				$this->head();
207
				$this->head();
219
				break;
208
				break;
Zeile 251... Zeile 240...
251
		return session_id();
240
		return session_id();
252
	}
241
	}
Zeile 253... Zeile 242...
253
 
242
 
254
	protected function get_user_path()
243
	protected function get_user_path()
255
	{
244
	{
256
		if ($this->options['user_dirs'])
-
 
257
		{
245
		if ($this->options['user_dirs']) {
258
			return $this->get_user_id() . '/';
246
			return $this->get_user_id() . '/';
259
		}
247
		}
260
		return '';
248
		return '';
Zeile 261... Zeile 249...
261
	}
249
	}
262
 
250
 
263
	protected function get_upload_path($file_name = null, $version = null)
251
	protected function get_upload_path($file_name = null, $version = null)
264
	{
252
	{
265
		$file_name = $file_name ? $file_name : '';
-
 
266
		if (empty($version))
253
		$file_name = $file_name ? $file_name : '';
267
		{
254
		if (empty($version)) {
268
			$version_path = '';
-
 
269
		} else
255
			$version_path = '';
270
		{
256
		} else {
271
			$version_dir = @$this->options['image_versions'][$version]['upload_dir'];
-
 
272
			if ($version_dir)
257
			$version_dir = @$this->options['image_versions'][$version]['upload_dir'];
273
			{
258
			if ($version_dir) {
274
				return $version_dir . $this->get_user_path() . $file_name;
259
				return $version_dir . $this->get_user_path() . $file_name;
275
			}
260
			}
276
			$version_path = $version . '/';
261
			$version_path = $version . '/';
Zeile 283... Zeile 268...
283
		return strpos($url, '?') === false ? '?' : '&';
268
		return strpos($url, '?') === false ? '?' : '&';
284
	}
269
	}
Zeile 285... Zeile 270...
285
 
270
 
286
	protected function get_download_url($file_name, $version = null, $direct = false)
271
	protected function get_download_url($file_name, $version = null, $direct = false)
287
	{
272
	{
288
		if (!$direct && $this->options['download_via_php'])
-
 
289
		{
273
		if (!$direct && $this->options['download_via_php']) {
290
			$url = $this->options['script_url'] . $this->get_query_separator($this->options['script_url']) .
274
			$url = $this->options['script_url'] . $this->get_query_separator($this->options['script_url']) .
291
				$this->get_singular_param_name() . '=' . rawurlencode($file_name);
275
				$this->get_singular_param_name() . '=' . rawurlencode($file_name);
292
			if ($version)
-
 
293
			{
276
			if ($version) {
294
				$url .= '&version=' . rawurlencode($version);
277
				$url .= '&version=' . rawurlencode($version);
295
			}
278
			}
296
			return $url . '&download=1';
279
			return $url . '&download=1';
297
		}
280
		}
298
		if (empty($version))
-
 
299
		{
281
		if (empty($version)) {
300
			$version_path = '';
282
			$version_path = '';
301
		} else
-
 
302
		{
283
		} else {
303
			$version_url = @$this->options['image_versions'][$version]['upload_url'];
284
			$version_url = @$this->options['image_versions'][$version]['upload_url'];
304
			if ($version_url)
-
 
305
			{
285
			if ($version_url) {
306
				return $version_url . $this->get_user_path() . rawurlencode($file_name);
286
				return $version_url . $this->get_user_path() . rawurlencode($file_name);
307
			}
287
			}
308
			$version_path = rawurlencode($version) . '/';
288
			$version_path = rawurlencode($version) . '/';
309
		}
289
		}
Zeile 315... Zeile 295...
315
	{
295
	{
316
		$file->deleteUrl = $this->options['script_url'] . $this->get_query_separator($this->
296
		$file->deleteUrl = $this->options['script_url'] . $this->get_query_separator($this->
317
			options['script_url']) . $this->get_singular_param_name() . '=' . rawurlencode($file->
297
			options['script_url']) . $this->get_singular_param_name() . '=' . rawurlencode($file->
318
			name);
298
			name);
319
		$file->deleteType = $this->options['delete_type'];
299
		$file->deleteType = $this->options['delete_type'];
320
		if ($file->deleteType !== 'DELETE')
300
		if ($file->deleteType !== 'DELETE') {
321
		{
-
 
322
			$file->deleteUrl .= '&_method=DELETE';
301
			$file->deleteUrl .= '&_method=DELETE';
323
		}
302
		}
-
 
303
        trigger_error($file->deleteUrl);
324
		if ($this->options['access_control_allow_credentials'])
304
		if ($this->options['access_control_allow_credentials']) {
325
		{
-
 
326
			$file->deleteWithCredentials = true;
305
			$file->deleteWithCredentials = true;
327
		}
306
		}
328
	}
307
	}
Zeile 329... Zeile 308...
329
 
308
 
330
	// Fix for overflowing signed 32 bit integers,
309
	// Fix for overflowing signed 32 bit integers,
331
	// works for sizes up to 2^32-1 bytes (4 GiB - 1):
310
	// works for sizes up to 2^32-1 bytes (4 GiB - 1):
332
	protected function fix_integer_overflow($size)
311
	protected function fix_integer_overflow($size)
333
	{
312
	{
334
		if ($size < 0)
-
 
335
		{
313
		if ($size < 0) {
336
			$size += 2.0 * (PHP_INT_MAX + 1);
314
			$size += 2.0 * (PHP_INT_MAX + 1);
337
		}
315
		}
338
		return $size;
316
		return $size;
Zeile 339... Zeile 317...
339
	}
317
	}
340
 
318
 
341
	protected function get_file_size($file_path, $clear_stat_cache = false)
319
	protected function get_file_size($file_path, $clear_stat_cache = false)
342
	{
-
 
343
		if ($clear_stat_cache)
320
	{
344
		{
-
 
345
			if (version_compare(PHP_VERSION, '5.3.0') >= 0)
321
		if ($clear_stat_cache) {
346
			{
322
			if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
347
				clearstatcache(true, $file_path);
-
 
348
			} else
323
				clearstatcache(true, $file_path);
349
			{
324
			} else {
350
				clearstatcache();
325
				clearstatcache();
351
			}
326
			}
352
		}
327
		}
Zeile 353... Zeile 328...
353
		return $this->fix_integer_overflow(filesize($file_path));
328
		return $this->fix_integer_overflow(filesize($file_path));
354
	}
329
	}
355
 
330
 
356
	protected function is_valid_file_object($file_name)
331
	protected function is_valid_file_object($file_name)
357
	{
-
 
358
		$file_path = $this->get_upload_path($file_name);
332
	{
359
		if (is_file($file_path) && $file_name[0] !== '.')
333
		$file_path = $this->get_upload_path($file_name);
360
		{
334
		if (is_file($file_path) && $file_name[0] !== '.') {
361
			return true;
335
			return true;
Zeile 362... Zeile 336...
362
		}
336
		}
363
		return false;
337
		return false;
364
	}
338
	}
365
 
-
 
366
	protected function get_file_object($file_name)
339
 
367
	{
340
	protected function get_file_object($file_name)
368
		if ($this->is_valid_file_object($file_name))
341
	{
369
		{
342
		if ($this->is_valid_file_object($file_name)) {
370
			$file = new \stdClass();
343
			$file = new \stdClass();
371
			$file->name = $file_name;
-
 
372
			$file->size = $this->get_file_size($this->get_upload_path($file_name));
344
			$file->name = $file_name;
373
			$file->url = $this->get_download_url($file->name);
-
 
374
			foreach ($this->options['image_versions'] as $version => $options)
345
			$file->size = $this->get_file_size($this->get_upload_path($file_name));
375
			{
-
 
376
				if (!empty($version))
346
			$file->url = $this->get_download_url($file->name);
377
				{
347
			foreach ($this->options['image_versions'] as $version => $options) {
378
					if (is_file($this->get_upload_path($file_name, $version)))
348
				if (!empty($version)) {
379
					{
349
					if (is_file($this->get_upload_path($file_name, $version))) {
380
						$file->{$version . 'Url'} = $this->get_download_url($file->name, $version);
350
						$file->{$version . 'Url'} = $this->get_download_url($file->name, $version);
Zeile 388... Zeile 358...
388
	}
358
	}
Zeile 389... Zeile 359...
389
 
359
 
390
	protected function get_file_objects($iteration_method = 'get_file_object')
360
	protected function get_file_objects($iteration_method = 'get_file_object')
391
	{
361
	{
392
		$upload_dir = $this->get_upload_path();
362
		$upload_dir = $this->get_upload_path();
393
		if (!is_dir($upload_dir))
-
 
394
		{
363
		if (!is_dir($upload_dir)) {
395
			return array();
364
			return array();
396
		}
365
		}
397
		return array_values(array_filter(array_map(array($this, $iteration_method),
366
		return array_values(array_filter(array_map(array($this, $iteration_method),
398
			scandir($upload_dir))));
367
			scandir($upload_dir))));
Zeile 411... Zeile 380...
411
	public function get_config_bytes($val)
380
	public function get_config_bytes($val)
412
	{
381
	{
413
		$val = trim($val);
382
		$val = trim($val);
414
		$last = strtolower($val[strlen($val) - 1]);
383
		$last = strtolower($val[strlen($val) - 1]);
415
		$val = (int)$val;
384
		$val = (int)$val;
416
		switch ($last)
385
		switch ($last) {
417
		{
-
 
418
			case 'g':
386
			case 'g':
419
				$val *= 1024;
387
				$val *= 1024;
420
			case 'm':
388
			case 'm':
421
				$val *= 1024;
389
				$val *= 1024;
422
			case 'k':
390
			case 'k':
Zeile 425... Zeile 393...
425
		return $this->fix_integer_overflow($val);
393
		return $this->fix_integer_overflow($val);
426
	}
394
	}
Zeile 427... Zeile 395...
427
 
395
 
428
	protected function validate($uploaded_file, $file, $error, $index)
396
	protected function validate($uploaded_file, $file, $error, $index)
429
	{
397
	{
430
		if ($error)
-
 
431
		{
398
		if ($error) {
432
			$file->error = $this->get_error_message($error);
399
			$file->error = $this->get_error_message($error);
433
			return false;
400
			return false;
434
		}
401
		}
435
		$content_length = $this->fix_integer_overflow((int)$this->get_server_var('CONTENT_LENGTH'));
402
		$content_length = $this->fix_integer_overflow((int)$this->get_server_var('CONTENT_LENGTH'));
436
		$post_max_size = $this->get_config_bytes(ini_get('post_max_size'));
403
		$post_max_size = $this->get_config_bytes(ini_get('post_max_size'));
437
		if ($post_max_size && ($content_length > $post_max_size))
-
 
438
		{
404
		if ($post_max_size && ($content_length > $post_max_size)) {
439
			$file->error = $this->get_error_message('post_max_size');
405
			$file->error = $this->get_error_message('post_max_size');
440
			return false;
406
			return false;
441
		}
407
		}
442
		if (!preg_match($this->options['accept_file_types'], $file->name))
-
 
443
		{
408
		if (!preg_match($this->options['accept_file_types'], $file->name)) {
444
			$file->error = $this->get_error_message('accept_file_types');
409
			$file->error = $this->get_error_message('accept_file_types');
445
			return false;
410
			return false;
446
		}
411
		}
447
		if ($uploaded_file && is_uploaded_file($uploaded_file))
-
 
448
		{
412
		if ($uploaded_file && is_uploaded_file($uploaded_file)) {
449
			$file_size = $this->get_file_size($uploaded_file);
413
			$file_size = $this->get_file_size($uploaded_file);
450
		} else
-
 
451
		{
414
		} else {
452
			$file_size = $content_length;
415
			$file_size = $content_length;
453
		}
416
		}
454
		if ($this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] ||
417
		if ($this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] ||
455
			$file->size > $this->options['max_file_size']))
-
 
456
		{
418
			$file->size > $this->options['max_file_size'])) {
457
			$file->error = $this->get_error_message('max_file_size');
419
			$file->error = $this->get_error_message('max_file_size');
458
			return false;
420
			return false;
459
		}
421
		}
460
		if ($this->options['min_file_size'] && $file_size < $this->options['min_file_size'])
-
 
461
		{
422
		if ($this->options['min_file_size'] && $file_size < $this->options['min_file_size']) {
462
			$file->error = $this->get_error_message('min_file_size');
423
			$file->error = $this->get_error_message('min_file_size');
463
			return false;
424
			return false;
464
		}
425
		}
465
		if (is_int($this->options['max_number_of_files']) && ($this->count_file_objects
426
		if (is_int($this->options['max_number_of_files']) && ($this->count_file_objects
466
			() >= $this->options['max_number_of_files']) &&
427
			() >= $this->options['max_number_of_files']) &&
467
			// Ignore additional chunks of existing files:
428
			// Ignore additional chunks of existing files:
468
			!is_file($this->get_upload_path($file->name)))
-
 
469
		{
429
			!is_file($this->get_upload_path($file->name))) {
470
			$file->error = $this->get_error_message('max_number_of_files');
430
			$file->error = $this->get_error_message('max_number_of_files');
471
			return false;
431
			return false;
472
		}
432
		}
473
		$max_width = @$this->options['max_width'];
433
		$max_width = @$this->options['max_width'];
474
		$max_height = @$this->options['max_height'];
434
		$max_height = @$this->options['max_height'];
475
		$min_width = @$this->options['min_width'];
435
		$min_width = @$this->options['min_width'];
476
		$min_height = @$this->options['min_height'];
436
		$min_height = @$this->options['min_height'];
477
		if (($max_width || $max_height || $min_width || $min_height) && preg_match($this->
437
		if (($max_width || $max_height || $min_width || $min_height) && preg_match($this->
478
			options['image_file_types'], $file->name))
-
 
479
		{
438
			options['image_file_types'], $file->name)) {
Zeile 480... Zeile 439...
480
			list($img_width, $img_height) = $this->get_image_size($uploaded_file);
439
			list($img_width, $img_height) = $this->get_image_size($uploaded_file);
481
 
440
 
482
			// If we are auto rotating the image by default, do the checks on
441
			// If we are auto rotating the image by default, do the checks on
483
			// the correct orientation
442
			// the correct orientation
484
			if (@$this->options['image_versions']['']['auto_orient'] && function_exists('exif_read_data') &&
-
 
485
				($exif = @exif_read_data($uploaded_file)) && (((int)@$exif['Orientation']) >= 5))
443
			if (@$this->options['image_versions']['']['auto_orient'] && function_exists('exif_read_data') &&
486
			{
444
				($exif = @exif_read_data($uploaded_file)) && (((int)@$exif['Orientation']) >= 5)) {
487
				$tmp = $img_width;
445
				$tmp = $img_width;
488
				$img_width = $img_height;
446
				$img_width = $img_height;
489
				$img_height = $tmp;
447
				$img_height = $tmp;
Zeile 490... Zeile 448...
490
				unset($tmp);
448
				unset($tmp);
491
			}
449
			}
492
 
-
 
493
		}
450
 
494
		if (!empty($img_width))
-
 
495
		{
451
		}
496
			if ($max_width && $img_width > $max_width)
452
		if (!empty($img_width)) {
497
			{
453
			if ($max_width && $img_width > $max_width) {
498
				$file->error = $this->get_error_message('max_width');
454
				$file->error = $this->get_error_message('max_width');
499
				return false;
-
 
500
			}
455
				return false;
501
			if ($max_height && $img_height > $max_height)
456
			}
502
			{
457
			if ($max_height && $img_height > $max_height) {
503
				$file->error = $this->get_error_message('max_height');
458
				$file->error = $this->get_error_message('max_height');
504
				return false;
-
 
505
			}
459
				return false;
506
			if ($min_width && $img_width < $min_width)
460
			}
507
			{
461
			if ($min_width && $img_width < $min_width) {
508
				$file->error = $this->get_error_message('min_width');
462
				$file->error = $this->get_error_message('min_width');
509
				return false;
-
 
510
			}
463
				return false;
511
			if ($min_height && $img_height < $min_height)
464
			}
512
			{
465
			if ($min_height && $img_height < $min_height) {
513
				$file->error = $this->get_error_message('min_height');
466
				$file->error = $this->get_error_message('min_height');
514
				return false;
467
				return false;
Zeile 531... Zeile 484...
531
	}
484
	}
Zeile 532... Zeile 485...
532
 
485
 
533
	protected function get_unique_filename($file_path, $name, $size, $type, $error,
486
	protected function get_unique_filename($file_path, $name, $size, $type, $error,
534
		$index, $content_range)
487
		$index, $content_range)
535
	{
488
	{
536
		while (is_dir($this->get_upload_path($name)))
-
 
537
		{
489
		while (is_dir($this->get_upload_path($name))) {
538
			$name = $this->upcount_name($name);
490
			$name = $this->upcount_name($name);
539
		}
491
		}
540
		// Keep an existing filename if this is part of a chunked upload:
492
		// Keep an existing filename if this is part of a chunked upload:
541
		$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
493
		$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
542
		while (is_file($this->get_upload_path($name)))
-
 
543
		{
494
		while (is_file($this->get_upload_path($name))) {
544
			if ($uploaded_bytes === $this->get_file_size($this->get_upload_path($name)))
-
 
545
			{
495
			if ($uploaded_bytes === $this->get_file_size($this->get_upload_path($name))) {
546
				break;
496
				break;
547
			}
497
			}
548
			$name = $this->upcount_name($name);
498
			$name = $this->upcount_name($name);
549
		}
499
		}
Zeile 553... Zeile 503...
553
	protected function fix_file_extension($file_path, $name, $size, $type, $error, $index,
503
	protected function fix_file_extension($file_path, $name, $size, $type, $error, $index,
554
		$content_range)
504
		$content_range)
555
	{
505
	{
556
		// Add missing file extension for known image types:
506
		// Add missing file extension for known image types:
557
		if (strpos($name, '.') === false && preg_match('/^image\/(gif|jpe?g|png)/', $type,
507
		if (strpos($name, '.') === false && preg_match('/^image\/(gif|jpe?g|png)/', $type,
558
			$matches))
508
			$matches)) {
559
		{
-
 
560
			$name .= '.' . $matches[1];
509
			$name .= '.' . $matches[1];
561
		}
510
		}
562
		if ($this->options['correct_image_extensions'] && function_exists('exif_imagetype'))
511
		if ($this->options['correct_image_extensions'] && function_exists('exif_imagetype')) {
563
		{
-
 
564
			switch (@exif_imagetype($file_path))
512
			switch (@exif_imagetype($file_path)) {
565
			{
-
 
566
				case IMAGETYPE_JPEG:
513
				case IMAGETYPE_JPEG:
567
					$extensions = array('jpg', 'jpeg');
514
					$extensions = array('jpg', 'jpeg');
568
					break;
515
					break;
569
				case IMAGETYPE_PNG:
516
				case IMAGETYPE_PNG:
570
					$extensions = array('png');
517
					$extensions = array('png');
Zeile 572... Zeile 519...
572
				case IMAGETYPE_GIF:
519
				case IMAGETYPE_GIF:
573
					$extensions = array('gif');
520
					$extensions = array('gif');
574
					break;
521
					break;
575
			}
522
			}
576
			// Adjust incorrect image file extensions:
523
			// Adjust incorrect image file extensions:
577
			if (!empty($extensions))
524
			if (!empty($extensions)) {
578
			{
-
 
579
				$parts = explode('.', $name);
525
				$parts = explode('.', $name);
580
				$extIndex = count($parts) - 1;
526
				$extIndex = count($parts) - 1;
581
				$ext = strtolower(@$parts[$extIndex]);
527
				$ext = strtolower(@$parts[$extIndex]);
582
				if (!in_array($ext, $extensions))
528
				if (!in_array($ext, $extensions)) {
583
				{
-
 
584
					$parts[$extIndex] = $extensions[0];
529
					$parts[$extIndex] = $extensions[0];
585
					$name = implode('.', $parts);
530
					$name = implode('.', $parts);
586
				}
531
				}
587
			}
532
			}
588
		}
533
		}
Zeile 595... Zeile 540...
595
		// Remove path information and dots around the filename, to prevent uploading
540
		// Remove path information and dots around the filename, to prevent uploading
596
		// into different directories or replacing hidden system files.
541
		// into different directories or replacing hidden system files.
597
		// Also remove control characters and spaces (\x00..\x20) around the filename:
542
		// Also remove control characters and spaces (\x00..\x20) around the filename:
598
		$name = trim($this->basename(stripslashes($name)), ".\x00..\x20");
543
		$name = trim($this->basename(stripslashes($name)), ".\x00..\x20");
599
		// Use a timestamp for empty filenames:
544
		// Use a timestamp for empty filenames:
600
		if (!$name)
545
		if (!$name) {
601
		{
-
 
602
			$name = str_replace('.', '-', microtime(true));
546
			$name = str_replace('.', '-', microtime(true));
603
		}
547
		}
604
		return $name;
548
		return $name;
605
	}
549
	}
Zeile 614... Zeile 558...
614
	}
558
	}
Zeile 615... Zeile 559...
615
 
559
 
616
	protected function get_scaled_image_file_paths($file_name, $version)
560
	protected function get_scaled_image_file_paths($file_name, $version)
617
	{
561
	{
618
		$file_path = $this->get_upload_path($file_name);
562
		$file_path = $this->get_upload_path($file_name);
619
		if (!empty($version))
-
 
620
		{
563
		if (!empty($version)) {
621
			$version_dir = $this->get_upload_path(null, $version);
564
			$version_dir = $this->get_upload_path(null, $version);
622
			if (!is_dir($version_dir))
-
 
623
			{
565
			if (!is_dir($version_dir)) {
624
				mkdir($version_dir, $this->options['mkdir_mode'], true);
566
				mkdir($version_dir, $this->options['mkdir_mode'], true);
625
			}
567
			}
626
			$new_file_path = $version_dir . '/' . $file_name;
568
			$new_file_path = $version_dir . '/' . $file_name;
627
		} else
-
 
628
		{
569
		} else {
629
			$new_file_path = $file_path;
570
			$new_file_path = $file_path;
630
		}
571
		}
631
		return array($file_path, $new_file_path);
572
		return array($file_path, $new_file_path);
Zeile 632... Zeile 573...
632
	}
573
	}
633
 
574
 
634
	protected function gd_get_image_object($file_path, $func, $no_cache = false)
575
	protected function gd_get_image_object($file_path, $func, $no_cache = false)
635
	{
-
 
636
		if (empty($this->image_objects[$file_path]) || $no_cache)
576
	{
637
		{
577
		if (empty($this->image_objects[$file_path]) || $no_cache) {
638
			$this->gd_destroy_image_object($file_path);
578
			$this->gd_destroy_image_object($file_path);
639
			$this->image_objects[$file_path] = $func($file_path);
579
			$this->image_objects[$file_path] = $func($file_path);
640
		}
580
		}
Zeile 653... Zeile 593...
653
		return $image && imagedestroy($image);
593
		return $image && imagedestroy($image);
654
	}
594
	}
Zeile 655... Zeile 595...
655
 
595
 
656
	protected function gd_imageflip($image, $mode)
596
	protected function gd_imageflip($image, $mode)
657
	{
597
	{
658
		if (function_exists('imageflip'))
-
 
659
		{
598
		if (function_exists('imageflip')) {
660
			return imageflip($image, $mode);
599
			return imageflip($image, $mode);
661
		}
600
		}
662
		$new_width = $src_width = imagesx($image);
601
		$new_width = $src_width = imagesx($image);
663
		$new_height = $src_height = imagesy($image);
602
		$new_height = $src_height = imagesy($image);
664
		$new_img = imagecreatetruecolor($new_width, $new_height);
603
		$new_img = imagecreatetruecolor($new_width, $new_height);
665
		$src_x = 0;
604
		$src_x = 0;
666
		$src_y = 0;
605
		$src_y = 0;
667
		switch ($mode)
-
 
668
		{
606
		switch ($mode) {
669
			case '1': // flip on the horizontal axis
607
			case '1': // flip on the horizontal axis
670
				$src_y = $new_height - 1;
608
				$src_y = $new_height - 1;
671
				$src_height = -$new_height;
609
				$src_height = -$new_height;
672
				break;
610
				break;
Zeile 688... Zeile 626...
688
		return $new_img;
626
		return $new_img;
689
	}
627
	}
Zeile 690... Zeile 628...
690
 
628
 
691
	protected function gd_orient_image($file_path, $src_img)
629
	protected function gd_orient_image($file_path, $src_img)
692
	{
630
	{
693
		if (!function_exists('exif_read_data'))
-
 
694
		{
631
		if (!function_exists('exif_read_data')) {
695
			return false;
632
			return false;
696
		}
633
		}
697
		$exif = @exif_read_data($file_path);
634
		$exif = @exif_read_data($file_path);
698
		if ($exif === false)
-
 
699
		{
635
		if ($exif === false) {
700
			return false;
636
			return false;
701
		}
637
		}
702
		$orientation = (int)@$exif['Orientation'];
638
		$orientation = (int)@$exif['Orientation'];
703
		if ($orientation < 2 || $orientation > 8)
-
 
704
		{
639
		if ($orientation < 2 || $orientation > 8) {
705
			return false;
640
			return false;
706
		}
641
		}
707
		switch ($orientation)
-
 
708
		{
642
		switch ($orientation) {
709
			case 2:
643
			case 2:
710
				$new_img = $this->gd_imageflip($src_img, defined('IMG_FLIP_VERTICAL') ?
644
				$new_img = $this->gd_imageflip($src_img, defined('IMG_FLIP_VERTICAL') ?
711
					IMG_FLIP_VERTICAL : 2);
645
					IMG_FLIP_VERTICAL : 2);
712
				break;
646
				break;
Zeile 742... Zeile 676...
742
		return true;
676
		return true;
743
	}
677
	}
Zeile 744... Zeile 678...
744
 
678
 
745
	protected function gd_create_scaled_image($file_name, $version, $options)
679
	protected function gd_create_scaled_image($file_name, $version, $options)
746
	{
680
	{
747
		if (!function_exists('imagecreatetruecolor'))
-
 
748
		{
681
		if (!function_exists('imagecreatetruecolor')) {
749
			error_log('Function not found: imagecreatetruecolor');
682
			error_log('Function not found: imagecreatetruecolor');
750
			return false;
683
			return false;
751
		}
684
		}
752
		list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name,
685
		list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name,
753
			$version);
686
			$version);
754
		$type = strtolower(substr(strrchr($file_name, '.'), 1));
687
		$type = strtolower(substr(strrchr($file_name, '.'), 1));
755
		switch ($type)
-
 
756
		{
688
		switch ($type) {
757
			case 'jpg':
689
			case 'jpg':
758
			case 'jpeg':
690
			case 'jpeg':
759
				$src_func = 'imagecreatefromjpeg';
691
				$src_func = 'imagecreatefromjpeg';
760
				$write_func = 'imagejpeg';
692
				$write_func = 'imagejpeg';
Zeile 773... Zeile 705...
773
			default:
705
			default:
774
				return false;
706
				return false;
775
		}
707
		}
776
		$src_img = $this->gd_get_image_object($file_path, $src_func, !empty($options['no_cache']));
708
		$src_img = $this->gd_get_image_object($file_path, $src_func, !empty($options['no_cache']));
777
		$image_oriented = false;
709
		$image_oriented = false;
778
		if (!empty($options['auto_orient']) && $this->gd_orient_image($file_path, $src_img))
710
		if (!empty($options['auto_orient']) && $this->gd_orient_image($file_path, $src_img)) {
779
		{
-
 
780
			$image_oriented = true;
711
			$image_oriented = true;
781
			$src_img = $this->gd_get_image_object($file_path, $src_func);
712
			$src_img = $this->gd_get_image_object($file_path, $src_func);
782
		}
713
		}
783
		$max_width = $img_width = imagesx($src_img);
714
		$max_width = $img_width = imagesx($src_img);
784
		$max_height = $img_height = imagesy($src_img);
715
		$max_height = $img_height = imagesy($src_img);
785
		if (!empty($options['max_width']))
716
		if (!empty($options['max_width'])) {
786
		{
-
 
787
			$max_width = $options['max_width'];
717
			$max_width = $options['max_width'];
788
		}
718
		}
789
		if (!empty($options['max_height']))
719
		if (!empty($options['max_height'])) {
790
		{
-
 
791
			$max_height = $options['max_height'];
720
			$max_height = $options['max_height'];
792
		}
721
		}
793
		$scale = min($max_width / $img_width, $max_height / $img_height);
722
		$scale = min($max_width / $img_width, $max_height / $img_height);
794
		if ($scale >= 1)
723
		if ($scale >= 1) {
795
		{
-
 
796
			if ($image_oriented)
724
			if ($image_oriented) {
797
			{
-
 
798
				return $write_func($src_img, $new_file_path, $image_quality);
725
				return $write_func($src_img, $new_file_path, $image_quality);
799
			}
726
			}
800
			if ($file_path !== $new_file_path)
727
			if ($file_path !== $new_file_path) {
801
			{
-
 
802
				return copy($file_path, $new_file_path);
728
				return copy($file_path, $new_file_path);
803
			}
729
			}
804
			return true;
730
			return true;
805
		}
731
		}
806
		if (empty($options['crop']))
732
		if (empty($options['crop'])) {
807
		{
-
 
808
			$new_width = $img_width * $scale;
733
			$new_width = $img_width * $scale;
809
			$new_height = $img_height * $scale;
734
			$new_height = $img_height * $scale;
810
			$dst_x = 0;
735
			$dst_x = 0;
811
			$dst_y = 0;
736
			$dst_y = 0;
812
			$new_img = imagecreatetruecolor($new_width, $new_height);
737
			$new_img = imagecreatetruecolor($new_width, $new_height);
813
		} else
738
		} else {
814
		{
-
 
815
			if (($img_width / $img_height) >= ($max_width / $max_height))
739
			if (($img_width / $img_height) >= ($max_width / $max_height)) {
816
			{
-
 
817
				$new_width = $img_width / ($img_height / $max_height);
740
				$new_width = $img_width / ($img_height / $max_height);
818
				$new_height = $max_height;
741
				$new_height = $max_height;
819
			} else
742
			} else {
820
			{
-
 
821
				$new_width = $max_width;
743
				$new_width = $max_width;
822
				$new_height = $img_height / ($img_width / $max_width);
744
				$new_height = $img_height / ($img_width / $max_width);
823
			}
745
			}
824
			$dst_x = 0 - ($new_width - $max_width) / 2;
746
			$dst_x = 0 - ($new_width - $max_width) / 2;
825
			$dst_y = 0 - ($new_height - $max_height) / 2;
747
			$dst_y = 0 - ($new_height - $max_height) / 2;
826
			$new_img = imagecreatetruecolor($max_width, $max_height);
748
			$new_img = imagecreatetruecolor($max_width, $max_height);
827
		}
749
		}
828
		// Handle transparency in GIF and PNG images:
750
		// Handle transparency in GIF and PNG images:
829
		switch ($type)
751
		switch ($type) {
830
		{
-
 
831
			case 'gif':
752
			case 'gif':
832
			case 'png':
753
			case 'png':
833
				imagecolortransparent($new_img, imagecolorallocate($new_img, 0, 0, 0));
754
				imagecolortransparent($new_img, imagecolorallocate($new_img, 0, 0, 0));
834
			case 'png':
755
			case 'png':
835
				imagealphablending($new_img, false);
756
				imagealphablending($new_img, false);
Zeile 842... Zeile 763...
842
		return $success;
763
		return $success;
843
	}
764
	}
Zeile 844... Zeile 765...
844
 
765
 
845
	protected function imagick_get_image_object($file_path, $no_cache = false)
766
	protected function imagick_get_image_object($file_path, $no_cache = false)
846
	{
767
	{
847
		if (empty($this->image_objects[$file_path]) || $no_cache)
-
 
848
		{
768
		if (empty($this->image_objects[$file_path]) || $no_cache) {
849
			$this->imagick_destroy_image_object($file_path);
769
			$this->imagick_destroy_image_object($file_path);
850
			$image = new \Imagick();
770
			$image = new \Imagick();
851
			if (!empty($this->options['imagick_resource_limits']))
-
 
852
			{
771
			if (!empty($this->options['imagick_resource_limits'])) {
853
				foreach ($this->options['imagick_resource_limits'] as $type => $limit)
-
 
854
				{
772
				foreach ($this->options['imagick_resource_limits'] as $type => $limit) {
855
					$image->setResourceLimit($type, $limit);
773
					$image->setResourceLimit($type, $limit);
856
				}
774
				}
857
			}
775
			}
858
			$image->readImage($file_path);
776
			$image->readImage($file_path);
Zeile 875... Zeile 793...
875
 
793
 
876
	protected function imagick_orient_image($image)
794
	protected function imagick_orient_image($image)
877
	{
795
	{
878
		$orientation = $image->getImageOrientation();
796
		$orientation = $image->getImageOrientation();
879
		$background = new \ImagickPixel('none');
797
		$background = new \ImagickPixel('none');
880
		switch ($orientation)
-
 
881
		{
798
		switch ($orientation) {
882
			case \imagick::ORIENTATION_TOPRIGHT: // 2
799
			case \imagick::ORIENTATION_TOPRIGHT: // 2
883
				$image->flopImage(); // horizontal flop around y-axis
800
				$image->flopImage(); // horizontal flop around y-axis
884
				break;
801
				break;
885
			case \imagick::ORIENTATION_BOTTOMRIGHT: // 3
802
			case \imagick::ORIENTATION_BOTTOMRIGHT: // 3
Zeile 913... Zeile 830...
913
	{
830
	{
914
		list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name,
831
		list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name,
915
			$version);
832
			$version);
916
		$image = $this->imagick_get_image_object($file_path, !empty($options['crop']) ||
833
		$image = $this->imagick_get_image_object($file_path, !empty($options['crop']) ||
917
			!empty($options['no_cache']));
834
			!empty($options['no_cache']));
918
		if ($image->getImageFormat() === 'GIF')
835
		if ($image->getImageFormat() === 'GIF') {
919
		{
-
 
920
			// Handle animated GIFs:
836
			// Handle animated GIFs:
921
			$images = $image->coalesceImages();
837
			$images = $image->coalesceImages();
922
			foreach ($images as $frame)
838
			foreach ($images as $frame) {
923
			{
-
 
924
				$image = $frame;
839
				$image = $frame;
925
				$this->imagick_set_image_object($file_name, $image);
840
				$this->imagick_set_image_object($file_name, $image);
926
				break;
841
				break;
927
			}
842
			}
928
		}
843
		}
929
		$image_oriented = false;
844
		$image_oriented = false;
930
		if (!empty($options['auto_orient']))
845
		if (!empty($options['auto_orient'])) {
931
		{
-
 
932
			$image_oriented = $this->imagick_orient_image($image);
846
			$image_oriented = $this->imagick_orient_image($image);
933
		}
847
		}
934
		$new_width = $max_width = $img_width = $image->getImageWidth();
848
		$new_width = $max_width = $img_width = $image->getImageWidth();
935
		$new_height = $max_height = $img_height = $image->getImageHeight();
849
		$new_height = $max_height = $img_height = $image->getImageHeight();
936
		if (!empty($options['max_width']))
850
		if (!empty($options['max_width'])) {
937
		{
-
 
938
			$new_width = $max_width = $options['max_width'];
851
			$new_width = $max_width = $options['max_width'];
939
		}
852
		}
940
		if (!empty($options['max_height']))
853
		if (!empty($options['max_height'])) {
941
		{
-
 
942
			$new_height = $max_height = $options['max_height'];
854
			$new_height = $max_height = $options['max_height'];
943
		}
855
		}
944
		$image_strip = false;
856
		$image_strip = false;
945
		if (!empty($options["strip"]))
857
		if (!empty($options["strip"])) {
946
		{
-
 
947
			$image_strip = $options["strip"];
858
			$image_strip = $options["strip"];
948
		}
859
		}
949
		if (!$image_oriented && ($max_width >= $img_width) && ($max_height >= $img_height) &&
860
		if (!$image_oriented && ($max_width >= $img_width) && ($max_height >= $img_height) &&
950
			!$image_strip && empty($options["jpeg_quality"]))
861
			!$image_strip && empty($options["jpeg_quality"])) {
951
		{
-
 
952
			if ($file_path !== $new_file_path)
862
			if ($file_path !== $new_file_path) {
953
			{
-
 
954
				return copy($file_path, $new_file_path);
863
				return copy($file_path, $new_file_path);
955
			}
864
			}
956
			return true;
865
			return true;
957
		}
866
		}
958
		$crop = !empty($options['crop']);
867
		$crop = !empty($options['crop']);
959
		if ($crop)
868
		if ($crop) {
960
		{
-
 
961
			$x = 0;
869
			$x = 0;
962
			$y = 0;
870
			$y = 0;
963
			if (($img_width / $img_height) >= ($max_width / $max_height))
871
			if (($img_width / $img_height) >= ($max_width / $max_height)) {
964
			{
-
 
965
				$new_width = 0; // Enables proportional scaling based on max_height
872
				$new_width = 0; // Enables proportional scaling based on max_height
966
				$x = ($img_width / ($img_height / $max_height) - $max_width) / 2;
873
				$x = ($img_width / ($img_height / $max_height) - $max_width) / 2;
967
			} else
874
			} else {
968
			{
-
 
969
				$new_height = 0; // Enables proportional scaling based on max_width
875
				$new_height = 0; // Enables proportional scaling based on max_width
970
				$y = ($img_height / ($img_width / $max_width) - $max_height) / 2;
876
				$y = ($img_height / ($img_width / $max_width) - $max_height) / 2;
971
			}
877
			}
972
		}
878
		}
973
		$success = $image->resizeImage($new_width, $new_height, isset($options['filter']) ?
879
		$success = $image->resizeImage($new_width, $new_height, isset($options['filter']) ?
974
			$options['filter'] : \imagick::FILTER_LANCZOS, isset($options['blur']) ? $options['blur'] :
880
			$options['filter'] : \imagick::FILTER_LANCZOS, isset($options['blur']) ? $options['blur'] :
975
			1, $new_width && $new_height // fit image into constraints if not to be cropped
881
			1, $new_width && $new_height // fit image into constraints if not to be cropped
976
			);
882
			);
977
		if ($success && $crop)
883
		if ($success && $crop) {
978
		{
-
 
979
			$success = $image->cropImage($max_width, $max_height, $x, $y);
884
			$success = $image->cropImage($max_width, $max_height, $x, $y);
980
			if ($success)
885
			if ($success) {
981
			{
-
 
982
				$success = $image->setImagePage($max_width, $max_height, 0, 0);
886
				$success = $image->setImagePage($max_width, $max_height, 0, 0);
983
			}
887
			}
984
		}
888
		}
985
		$type = strtolower(substr(strrchr($file_name, '.'), 1));
889
		$type = strtolower(substr(strrchr($file_name, '.'), 1));
986
		switch ($type)
890
		switch ($type) {
987
		{
-
 
988
			case 'jpg':
891
			case 'jpg':
989
			case 'jpeg':
892
			case 'jpeg':
990
				if (!empty($options['jpeg_quality']))
893
				if (!empty($options['jpeg_quality'])) {
991
				{
-
 
992
					$image->setImageCompression(\imagick::COMPRESSION_JPEG);
894
					$image->setImageCompression(\imagick::COMPRESSION_JPEG);
993
					$image->setImageCompressionQuality($options['jpeg_quality']);
895
					$image->setImageCompressionQuality($options['jpeg_quality']);
994
				}
896
				}
995
				break;
897
				break;
996
		}
898
		}
997
		if ($image_strip)
899
		if ($image_strip) {
998
		{
-
 
999
			$image->stripImage();
900
			$image->stripImage();
1000
		}
901
		}
1001
		return $success && $image->writeImage($new_file_path);
902
		return $success && $image->writeImage($new_file_path);
1002
	}
903
	}
Zeile 1003... Zeile 904...
1003
 
904
 
1004
	protected function imagemagick_create_scaled_image($file_name, $version, $options)
905
	protected function imagemagick_create_scaled_image($file_name, $version, $options)
1005
	{
906
	{
1006
		list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name,
907
		list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name,
1007
			$version);
908
			$version);
1008
		$resize = @$options['max_width'] . (empty($options['max_height']) ? '' : 'X' . $options['max_height']);
909
		$resize = @$options['max_width'] . (empty($options['max_height']) ? '' : 'X' . $options['max_height']);
1009
		if (!$resize && empty($options['auto_orient']))
-
 
1010
		{
910
		if (!$resize && empty($options['auto_orient'])) {
1011
			if ($file_path !== $new_file_path)
-
 
1012
			{
911
			if ($file_path !== $new_file_path) {
1013
				return copy($file_path, $new_file_path);
912
				return copy($file_path, $new_file_path);
1014
			}
913
			}
1015
			return true;
914
			return true;
1016
		}
915
		}
1017
		$cmd = $this->options['convert_bin'];
916
		$cmd = $this->options['convert_bin'];
1018
		if (!empty($this->options['convert_params']))
-
 
1019
		{
917
		if (!empty($this->options['convert_params'])) {
1020
			$cmd .= ' ' . $this->options['convert_params'];
918
			$cmd .= ' ' . $this->options['convert_params'];
1021
		}
919
		}
1022
		$cmd .= ' ' . escapeshellarg($file_path);
920
		$cmd .= ' ' . escapeshellarg($file_path);
1023
		if (!empty($options['auto_orient']))
-
 
1024
		{
921
		if (!empty($options['auto_orient'])) {
1025
			$cmd .= ' -auto-orient';
922
			$cmd .= ' -auto-orient';
1026
		}
923
		}
1027
		if ($resize)
-
 
1028
		{
924
		if ($resize) {
1029
			// Handle animated GIFs:
925
			// Handle animated GIFs:
1030
			$cmd .= ' -coalesce';
926
			$cmd .= ' -coalesce';
1031
			if (empty($options['crop']))
-
 
1032
			{
927
			if (empty($options['crop'])) {
1033
				$cmd .= ' -resize ' . escapeshellarg($resize . '>');
928
				$cmd .= ' -resize ' . escapeshellarg($resize . '>');
1034
			} else
-
 
1035
			{
929
			} else {
1036
				$cmd .= ' -resize ' . escapeshellarg($resize . '^');
930
				$cmd .= ' -resize ' . escapeshellarg($resize . '^');
1037
				$cmd .= ' -gravity center';
931
				$cmd .= ' -gravity center';
1038
				$cmd .= ' -crop ' . escapeshellarg($resize . '+0+0');
932
				$cmd .= ' -crop ' . escapeshellarg($resize . '+0+0');
1039
			}
933
			}
1040
			// Make sure the page dimensions are correct (fixes offsets of animated GIFs):
934
			// Make sure the page dimensions are correct (fixes offsets of animated GIFs):
1041
			$cmd .= ' +repage';
935
			$cmd .= ' +repage';
1042
		}
936
		}
1043
		if (!empty($options['convert_params']))
-
 
1044
		{
937
		if (!empty($options['convert_params'])) {
1045
			$cmd .= ' ' . $options['convert_params'];
938
			$cmd .= ' ' . $options['convert_params'];
1046
		}
939
		}
1047
		$cmd .= ' ' . escapeshellarg($new_file_path);
940
		$cmd .= ' ' . escapeshellarg($new_file_path);
1048
		exec($cmd, $output, $error);
941
		exec($cmd, $output, $error);
1049
		if ($error)
-
 
1050
		{
942
		if ($error) {
1051
			error_log(implode('\n', $output));
943
			error_log(implode('\n', $output));
1052
			return false;
944
			return false;
1053
		}
945
		}
1054
		return true;
946
		return true;
Zeile 1055... Zeile 947...
1055
	}
947
	}
1056
 
948
 
1057
	protected function get_image_size($file_path)
949
	protected function get_image_size($file_path)
1058
	{
-
 
1059
		if ($this->options['image_library'])
950
	{
1060
		{
-
 
1061
			if (extension_loaded('imagick'))
951
		if ($this->options['image_library']) {
1062
			{
952
			if (extension_loaded('imagick')) {
1063
				$image = new \Imagick();
-
 
1064
				try
953
				$image = new \Imagick();
1065
				{
-
 
1066
					if (@$image->pingImage($file_path))
954
				try {
1067
					{
955
					if (@$image->pingImage($file_path)) {
1068
						$dimensions = array($image->getImageWidth(), $image->getImageHeight());
956
						$dimensions = array($image->getImageWidth(), $image->getImageHeight());
1069
						$image->destroy();
957
						$image->destroy();
1070
						return $dimensions;
958
						return $dimensions;
1071
					}
959
					}
1072
					return false;
960
					return false;
1073
				}
-
 
1074
				catch (\Exception $e)
961
				}
1075
				{
962
				catch (\Exception $e) {
1076
					error_log($e->getMessage());
963
					error_log($e->getMessage());
1077
				}
964
				}
1078
			}
-
 
1079
			if ($this->options['image_library'] === 2)
965
			}
1080
			{
966
			if ($this->options['image_library'] === 2) {
1081
				$cmd = $this->options['identify_bin'];
967
				$cmd = $this->options['identify_bin'];
1082
				$cmd .= ' -ping ' . escapeshellarg($file_path);
968
				$cmd .= ' -ping ' . escapeshellarg($file_path);
1083
				exec($cmd, $output, $error);
-
 
1084
				if (!$error && !empty($output))
969
				exec($cmd, $output, $error);
1085
				{
970
				if (!$error && !empty($output)) {
1086
					// image.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 465KB 0.000u 0:00.000
971
					// image.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 465KB 0.000u 0:00.000
1087
					$infos = preg_split('/\s+/', substr($output[0], strlen($file_path)));
972
					$infos = preg_split('/\s+/', substr($output[0], strlen($file_path)));
1088
					$dimensions = preg_split('/x/', $infos[2]);
973
					$dimensions = preg_split('/x/', $infos[2]);
1089
					return $dimensions;
974
					return $dimensions;
1090
				}
975
				}
1091
				return false;
976
				return false;
1092
			}
977
			}
1093
		}
-
 
1094
		if (!function_exists('getimagesize'))
978
		}
1095
		{
979
		if (!function_exists('getimagesize')) {
1096
			error_log('Function not found: getimagesize');
980
			error_log('Function not found: getimagesize');
1097
			return false;
981
			return false;
1098
		}
982
		}
Zeile 1099... Zeile 983...
1099
		return @getimagesize($file_path);
983
		return @getimagesize($file_path);
1100
	}
984
	}
1101
 
985
 
1102
	protected function create_scaled_image($file_name, $version, $options)
-
 
1103
	{
986
	protected function create_scaled_image($file_name, $version, $options)
1104
		if ($this->options['image_library'] === 2)
987
	{
1105
		{
988
		if ($this->options['image_library'] === 2) {
1106
			return $this->imagemagick_create_scaled_image($file_name, $version, $options);
-
 
1107
		}
989
			return $this->imagemagick_create_scaled_image($file_name, $version, $options);
1108
		if ($this->options['image_library'] && extension_loaded('imagick'))
990
		}
1109
		{
991
		if ($this->options['image_library'] && extension_loaded('imagick')) {
1110
			return $this->imagick_create_scaled_image($file_name, $version, $options);
992
			return $this->imagick_create_scaled_image($file_name, $version, $options);
Zeile 1111... Zeile 993...
1111
		}
993
		}
1112
		return $this->gd_create_scaled_image($file_name, $version, $options);
994
		return $this->gd_create_scaled_image($file_name, $version, $options);
1113
	}
995
	}
1114
 
-
 
1115
	protected function destroy_image_object($file_path)
996
 
1116
	{
997
	protected function destroy_image_object($file_path)
1117
		if ($this->options['image_library'] && extension_loaded('imagick'))
998
	{
Zeile 1118... Zeile 999...
1118
		{
999
		if ($this->options['image_library'] && extension_loaded('imagick')) {
1119
			return $this->imagick_destroy_image_object($file_path);
1000
			return $this->imagick_destroy_image_object($file_path);
1120
		}
1001
		}
1121
	}
-
 
1122
 
1002
	}
1123
	protected function is_valid_image_file($file_path)
1003
 
1124
	{
1004
	protected function is_valid_image_file($file_path)
1125
		if (!preg_match($this->options['image_file_types'], $file_path))
-
 
1126
		{
1005
	{
1127
			return false;
1006
		if (!preg_match($this->options['image_file_types'], $file_path)) {
1128
		}
1007
			return false;
1129
		if (function_exists('exif_imagetype'))
1008
		}
1130
		{
1009
		if (function_exists('exif_imagetype')) {
Zeile 1131... Zeile 1010...
1131
			return @exif_imagetype($file_path);
1010
			return @exif_imagetype($file_path);
1132
		}
1011
		}
1133
		$image_info = $this->get_image_size($file_path);
1012
		$image_info = $this->get_image_size($file_path);
1134
		return $image_info && $image_info[0] && $image_info[1];
1013
		return $image_info && $image_info[0] && $image_info[1];
1135
	}
-
 
1136
 
1014
	}
1137
	protected function handle_image_file($file_path, $file)
-
 
1138
	{
1015
 
1139
		$failed_versions = array();
-
 
1140
		foreach ($this->options['image_versions'] as $version => $options)
1016
	protected function handle_image_file($file_path, $file)
1141
		{
1017
	{
1142
			if ($this->create_scaled_image($file->name, $version, $options))
-
 
1143
			{
1018
		$failed_versions = array();
1144
				if (!empty($version))
1019
		foreach ($this->options['image_versions'] as $version => $options) {
1145
				{
1020
			if ($this->create_scaled_image($file->name, $version, $options)) {
1146
					$file->{$version . 'Url'} = $this->get_download_url($file->name, $version);
-
 
1147
				} else
1021
				if (!empty($version)) {
1148
				{
1022
					$file->{$version . 'Url'} = $this->get_download_url($file->name, $version);
1149
					$file->size = $this->get_file_size($file_path, true);
1023
				} else {
1150
				}
1024
					$file->size = $this->get_file_size($file_path, true);
1151
			} else
-
 
1152
			{
1025
				}
1153
				$failed_versions[] = $version ? $version : 'original';
1026
			} else {
1154
			}
1027
				$failed_versions[] = $version ? $version : 'original';
1155
		}
1028
			}
1156
		if (count($failed_versions))
1029
		}
Zeile 1168... Zeile 1041...
1168
		$file = new \stdClass();
1041
		$file = new \stdClass();
1169
		$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
1042
		$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
1170
			$index, $content_range);
1043
			$index, $content_range);
1171
		$file->size = $this->fix_integer_overflow((int)$size);
1044
		$file->size = $this->fix_integer_overflow((int)$size);
1172
		$file->type = $type;
1045
		$file->type = $type;
1173
		if ($this->validate($uploaded_file, $file, $error, $index))
1046
		if ($this->validate($uploaded_file, $file, $error, $index)) {
1174
		{
-
 
1175
			$this->handle_form_data($file, $index);
1047
			$this->handle_form_data($file, $index);
1176
			$upload_dir = $this->get_upload_path();
1048
			$upload_dir = $this->get_upload_path();
1177
			if (!is_dir($upload_dir))
1049
			if (!is_dir($upload_dir)) {
1178
			{
-
 
1179
				mkdir($upload_dir, $this->options['mkdir_mode'], true);
1050
				mkdir($upload_dir, $this->options['mkdir_mode'], true);
1180
			}
1051
			}
1181
			$file_path = $this->get_upload_path($file->name);
1052
			$file_path = $this->get_upload_path($file->name);
1182
			$append_file = $content_range && is_file($file_path) && $file->size > $this->
1053
			$append_file = $content_range && is_file($file_path) && $file->size > $this->
1183
				get_file_size($file_path);
1054
				get_file_size($file_path);
1184
			if ($uploaded_file && is_uploaded_file($uploaded_file))
1055
			if ($uploaded_file && is_uploaded_file($uploaded_file)) {
1185
			{
-
 
1186
				// multipart/formdata uploads (POST method uploads)
1056
				// multipart/formdata uploads (POST method uploads)
1187
				if ($append_file)
1057
				if ($append_file) {
1188
				{
-
 
1189
					file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
1058
					file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
1190
				} else
1059
				} else {
1191
				{
-
 
1192
					move_uploaded_file($uploaded_file, $file_path);
1060
					move_uploaded_file($uploaded_file, $file_path);
1193
				}
1061
				}
1194
			} else
1062
			} else {
1195
			{
-
 
1196
				// Non-multipart uploads (PUT method support)
1063
				// Non-multipart uploads (PUT method support)
1197
				file_put_contents($file_path, fopen($this->options['input_stream'], 'r'), $append_file ?
1064
				file_put_contents($file_path, fopen($this->options['input_stream'], 'r'), $append_file ?
1198
					FILE_APPEND : 0);
1065
					FILE_APPEND : 0);
1199
			}
1066
			}
1200
			$file_size = $this->get_file_size($file_path, $append_file);
1067
			$file_size = $this->get_file_size($file_path, $append_file);
1201
			if ($file_size === $file->size)
1068
			$videos = array(
-
 
1069
				"wmf",
-
 
1070
				"flv",
-
 
1071
				"swf",
-
 
1072
				);
-
 
1073
			$docs = array(
-
 
1074
				"pdf",
-
 
1075
				"doc",
-
 
1076
				"docx",
-
 
1077
				"xls",
-
 
1078
				"xlsx",
1202
			{
1079
				);
-
 
1080
			if ($file_size === $file->size) {
1203
				$file->url = $this->get_download_url($file->name);
1081
				$file->url = $this->get_download_url($file->name);
1204
				if ($this->is_valid_image_file($file_path))
1082
				if ($this->is_valid_image_file($file_path)) {
1205
				{
-
 
1206
					$this->handle_image_file($file_path, $file);
1083
					$this->handle_image_file($file_path, $file);
1207
				}
1084
				}
-
 
1085
				$mt = mime_content_type($file_path);
-
 
1086
				$info = pathinfo($file_path);
-
 
1087
				$ext = strtolower($info["extension"]);
-
 
1088
				$typ = 4;
-
 
1089
				if (substr($mt, 0, 5) == "image") {
-
 
1090
					$typ = 1;
-
 
1091
					foreach ($this->options['image_versions'] as $version => $options) {
-
 
1092
						if ($this->create_scaled_image($fName, $options)) {
-
 
1093
							$file->{$version . '_url'} = $options['upload_url'] . $fName;
1208
			} else
1094
						}
-
 
1095
					}
-
 
1096
				} elseif (in_array($ext, $docs)) {
-
 
1097
					$typ = 2;
-
 
1098
				} elseif (in_array($ext, $videos)) {
-
 
1099
					$typ = 3;
1209
			{
1100
				}
-
 
1101
				$f = $GLOBALS["folder"];
-
 
1102
				$sql = "INSERT INTO
-
 
1103
                        medien
-
 
1104
                    SET
-
 
1105
                        name='" . $fName . "',
-
 
1106
                        folder='" . $f . "',
-
 
1107
                        erstellt_am=UNIX_TIMESTAMP(),
-
 
1108
                        erstellt_von='" . $_SERVER["PHP_AUTH_USER"] . "',
-
 
1109
                        typ=" . $typ . "
-
 
1110
                ";
-
 
1111
				$this->db->query($sql);
-
 
1112
			} else {
1210
				$file->size = $file_size;
1113
				$file->size = $file_size;
1211
				if (!$content_range && $this->options['discard_aborted_uploads'])
1114
				if (!$content_range && $this->options['discard_aborted_uploads']) {
1212
				{
-
 
1213
					unlink($file_path);
1115
					unlink($file_path);
1214
					$file->error = $this->get_error_message('abort');
1116
					$file->error = $this->get_error_message('abort');
1215
				}
1117
				}
1216
			}
1118
			}
1217
			$this->set_additional_file_properties($file);
1119
			$this->set_additional_file_properties($file);
Zeile 1221... Zeile 1123...
1221
 
1123
 
1222
	protected function readfile($file_path)
1124
	protected function readfile($file_path)
1223
	{
1125
	{
1224
		$file_size = $this->get_file_size($file_path);
1126
		$file_size = $this->get_file_size($file_path);
1225
		$chunk_size = $this->options['readfile_chunk_size'];
1127
		$chunk_size = $this->options['readfile_chunk_size'];
1226
		if ($chunk_size && $file_size > $chunk_size)
-
 
1227
		{
1128
		if ($chunk_size && $file_size > $chunk_size) {
1228
			$handle = fopen($file_path, 'rb');
1129
			$handle = fopen($file_path, 'rb');
1229
			while (!feof($handle))
-
 
1230
			{
1130
			while (!feof($handle)) {
1231
				echo fread($handle, $chunk_size);
1131
				echo fread($handle, $chunk_size);
1232
				@ob_flush();
1132
				@ob_flush();
1233
				@flush();
1133
				@flush();
1234
			}
1134
			}
Zeile 1290... Zeile 1190...
1290
	}
1190
	}
Zeile 1291... Zeile 1191...
1291
 
1191
 
1292
	protected function get_file_names_params()
1192
	protected function get_file_names_params()
1293
	{
1193
	{
1294
		$params = $this->get_query_param($this->options['param_name']);
1194
		$params = $this->get_query_param($this->options['param_name']);
1295
		if (!$params)
-
 
1296
		{
1195
		if (!$params) {
1297
			return null;
1196
			return null;
1298
		}
1197
		}
1299
		foreach ($params as $key => $value)
-
 
1300
		{
1198
		foreach ($params as $key => $value) {
1301
			$params[$key] = $this->basename(stripslashes($value));
1199
			$params[$key] = $this->basename(stripslashes($value));
1302
		}
1200
		}
1303
		return $params;
1201
		return $params;
Zeile 1304... Zeile 1202...
1304
	}
1202
	}
1305
 
1203
 
1306
	protected function get_file_type($file_path)
1204
	protected function get_file_type($file_path)
1307
	{
-
 
1308
		switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION)))
1205
	{
1309
		{
1206
		switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) {
1310
			case 'jpeg':
1207
			case 'jpeg':
1311
			case 'jpg':
1208
			case 'jpg':
1312
				return 'image/jpeg';
1209
				return 'image/jpeg';
1313
			case 'png':
1210
			case 'png':
1314
				return 'image/png';
1211
				return 'image/png';
-
 
1212
			case 'gif':
-
 
1213
				return 'image/gif';
1315
			case 'gif':
1214
			case 'svg':
1316
				return 'image/gif';
1215
				return 'image/svg';
1317
			default:
1216
			default:
1318
				return '';
1217
				return '';
Zeile 1319... Zeile 1218...
1319
		}
1218
		}
1320
	}
1219
	}
1321
 
1220
 
1322
	protected function download()
-
 
1323
	{
1221
	protected function download()
1324
		switch ($this->options['download_via_php'])
1222
	{
1325
		{
1223
		switch ($this->options['download_via_php']) {
1326
			case 1:
1224
			case 1:
1327
				$redirect_header = null;
1225
				$redirect_header = null;
Zeile 1334... Zeile 1232...
1334
				break;
1232
				break;
1335
			default:
1233
			default:
1336
				return $this->header('HTTP/1.1 403 Forbidden');
1234
				return $this->header('HTTP/1.1 403 Forbidden');
1337
		}
1235
		}
1338
		$file_name = $this->get_file_name_param();
1236
		$file_name = $this->get_file_name_param();
1339
		if (!$this->is_valid_file_object($file_name))
1237
		if (!$this->is_valid_file_object($file_name)) {
1340
		{
-
 
1341
			return $this->header('HTTP/1.1 404 Not Found');
1238
			return $this->header('HTTP/1.1 404 Not Found');
1342
		}
1239
		}
1343
		if ($redirect_header)
1240
		if ($redirect_header) {
1344
		{
-
 
1345
			return $this->header($redirect_header . ': ' . $this->get_download_url($file_name,
1241
			return $this->header($redirect_header . ': ' . $this->get_download_url($file_name,
1346
				$this->get_version_param(), true));
1242
				$this->get_version_param(), true));
1347
		}
1243
		}
1348
		$file_path = $this->get_upload_path($file_name, $this->get_version_param());
1244
		$file_path = $this->get_upload_path($file_name, $this->get_version_param());
1349
		// Prevent browsers from MIME-sniffing the content-type:
1245
		// Prevent browsers from MIME-sniffing the content-type:
1350
		$this->header('X-Content-Type-Options: nosniff');
1246
		$this->header('X-Content-Type-Options: nosniff');
1351
		if (!preg_match($this->options['inline_file_types'], $file_name))
1247
		if (!preg_match($this->options['inline_file_types'], $file_name)) {
1352
		{
-
 
1353
			$this->header('Content-Type: application/octet-stream');
1248
			$this->header('Content-Type: application/octet-stream');
1354
			$this->header('Content-Disposition: attachment; filename="' . $file_name . '"');
1249
			$this->header('Content-Disposition: attachment; filename="' . $file_name . '"');
1355
		} else
1250
		} else {
1356
		{
-
 
1357
			$this->header('Content-Type: ' . $this->get_file_type($file_path));
1251
			$this->header('Content-Type: ' . $this->get_file_type($file_path));
1358
			$this->header('Content-Disposition: inline; filename="' . $file_name . '"');
1252
			$this->header('Content-Disposition: inline; filename="' . $file_name . '"');
1359
		}
1253
		}
1360
		$this->header('Content-Length: ' . $this->get_file_size($file_path));
1254
		$this->header('Content-Length: ' . $this->get_file_size($file_path));
1361
		$this->header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', filemtime($file_path)));
1255
		$this->header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', filemtime($file_path)));
Zeile 1363... Zeile 1257...
1363
	}
1257
	}
Zeile 1364... Zeile 1258...
1364
 
1258
 
1365
	protected function send_content_type_header()
1259
	protected function send_content_type_header()
1366
	{
1260
	{
1367
		$this->header('Vary: Accept');
1261
		$this->header('Vary: Accept');
1368
		if (strpos($this->get_server_var('HTTP_ACCEPT'), 'application/json') !== false)
-
 
1369
		{
1262
		if (strpos($this->get_server_var('HTTP_ACCEPT'), 'application/json') !== false) {
1370
			$this->header('Content-type: application/json');
1263
			$this->header('Content-type: application/json');
1371
		} else
-
 
1372
		{
1264
		} else {
1373
			$this->header('Content-type: text/plain');
1265
			$this->header('Content-type: text/plain');
1374
		}
1266
		}
Zeile 1375... Zeile 1267...
1375
	}
1267
	}
Zeile 1384... Zeile 1276...
1384
	}
1276
	}
Zeile 1385... Zeile 1277...
1385
 
1277
 
1386
	public function generate_response($content, $print_response = true)
1278
	public function generate_response($content, $print_response = true)
1387
	{
1279
	{
1388
		$this->response = $content;
1280
		$this->response = $content;
1389
		if ($print_response)
-
 
1390
		{
1281
		if ($print_response) {
1391
			$json = json_encode($content);
1282
			$json = json_encode($content);
1392
			$redirect = stripslashes($this->get_post_param('redirect'));
1283
			$redirect = stripslashes($this->get_post_param('redirect'));
1393
			if ($redirect && preg_match($this->options['redirect_allow_target'], $redirect))
-
 
1394
			{
1284
			if ($redirect && preg_match($this->options['redirect_allow_target'], $redirect)) {
1395
				$this->header('Location: ' . sprintf($redirect, rawurlencode($json)));
1285
				$this->header('Location: ' . sprintf($redirect, rawurlencode($json)));
1396
				return;
1286
				return;
1397
			}
1287
			}
1398
			$this->head();
1288
			$this->head();
1399
			if ($this->get_server_var('HTTP_CONTENT_RANGE'))
-
 
1400
			{
1289
			if ($this->get_server_var('HTTP_CONTENT_RANGE')) {
1401
				$files = isset($content[$this->options['param_name']]) ? $content[$this->
1290
				$files = isset($content[$this->options['param_name']]) ? $content[$this->
1402
					options['param_name']] : null;
1291
					options['param_name']] : null;
1403
				if ($files && is_array($files) && is_object($files[0]) && $files[0]->size)
-
 
1404
				{
1292
				if ($files && is_array($files) && is_object($files[0]) && $files[0]->size) {
1405
					$this->header('Range: 0-' . ($this->fix_integer_overflow((int)$files[0]->size) -
1293
					$this->header('Range: 0-' . ($this->fix_integer_overflow((int)$files[0]->size) -
1406
						1));
1294
						1));
1407
				}
1295
				}
1408
			}
1296
			}
Zeile 1421... Zeile 1309...
1421
		$this->header('Pragma: no-cache');
1309
		$this->header('Pragma: no-cache');
1422
		$this->header('Cache-Control: no-store, no-cache, must-revalidate');
1310
		$this->header('Cache-Control: no-store, no-cache, must-revalidate');
1423
		$this->header('Content-Disposition: inline; filename="files.json"');
1311
		$this->header('Content-Disposition: inline; filename="files.json"');
1424
		// Prevent Internet Explorer from MIME-sniffing the content-type:
1312
		// Prevent Internet Explorer from MIME-sniffing the content-type:
1425
		$this->header('X-Content-Type-Options: nosniff');
1313
		$this->header('X-Content-Type-Options: nosniff');
1426
		if ($this->options['access_control_allow_origin'])
1314
		if ($this->options['access_control_allow_origin']) {
1427
		{
-
 
1428
			$this->send_access_control_headers();
1315
			$this->send_access_control_headers();
1429
		}
1316
		}
1430
		$this->send_content_type_header();
1317
		$this->send_content_type_header();
1431
	}
1318
	}
Zeile 1432... Zeile 1319...
1432
 
1319
 
1433
	public function get($print_response = true)
1320
	public function get($print_response = true)
1434
	{
1321
	{
1435
		if ($print_response && $this->get_query_param('download'))
-
 
1436
		{
1322
		if ($print_response && $this->get_query_param('download')) {
1437
			return $this->download();
1323
			return $this->download();
1438
		}
1324
		}
1439
		$file_name = $this->get_file_name_param();
1325
		$file_name = $this->get_file_name_param();
1440
		if ($file_name)
-
 
1441
		{
1326
		if ($file_name) {
1442
			$response = array($this->get_singular_param_name() => $this->get_file_object($file_name));
1327
			$response = array($this->get_singular_param_name() => $this->get_file_object($file_name));
1443
		} else
-
 
1444
		{
1328
		} else {
1445
			$response = array($this->options['param_name'] => $this->get_file_objects());
1329
			$response = array($this->options['param_name'] => $this->get_file_objects());
1446
		}
1330
		}
1447
		return $this->generate_response($response, $print_response);
1331
		return $this->generate_response($response, $print_response);
Zeile 1448... Zeile 1332...
1448
	}
1332
	}
1449
 
1333
 
1450
	public function post($print_response = true)
1334
	public function post($print_response = true)
1451
	{
-
 
1452
		if ($this->get_query_param('_method') === 'DELETE')
1335
	{
1453
		{
1336
		if ($this->get_query_param('_method') === 'DELETE') {
1454
			return $this->delete($print_response);
1337
			return $this->delete($print_response);
1455
		}
1338
		}
1456
		$upload = $this->get_upload_data($this->options['param_name']);
1339
		$upload = $this->get_upload_data($this->options['param_name']);
Zeile 1462... Zeile 1345...
1462
		// Content-Range: bytes 0-524287/2000000
1345
		// Content-Range: bytes 0-524287/2000000
1463
		$content_range_header = $this->get_server_var('HTTP_CONTENT_RANGE');
1346
		$content_range_header = $this->get_server_var('HTTP_CONTENT_RANGE');
1464
		$content_range = $content_range_header ? preg_split('/[^0-9]+/', $content_range_header) : null;
1347
		$content_range = $content_range_header ? preg_split('/[^0-9]+/', $content_range_header) : null;
1465
		$size = $content_range ? $content_range[3] : null;
1348
		$size = $content_range ? $content_range[3] : null;
1466
		$files = array();
1349
		$files = array();
1467
		if ($upload)
1350
		if ($upload) {
1468
		{
-
 
1469
			if (is_array($upload['tmp_name']))
1351
			if (is_array($upload['tmp_name'])) {
1470
			{
-
 
1471
				// param_name is an array identifier like "files[]",
1352
				// param_name is an array identifier like "files[]",
1472
				// $upload is a multi-dimensional array:
1353
				// $upload is a multi-dimensional array:
1473
				foreach ($upload['tmp_name'] as $index => $value)
1354
				foreach ($upload['tmp_name'] as $index => $value) {
1474
				{
-
 
1475
					$files[] = $this->handle_file_upload($upload['tmp_name'][$index], $file_name ? $file_name :
1355
					$files[] = $this->handle_file_upload($upload['tmp_name'][$index], $file_name ? $file_name :
1476
						$upload['name'][$index], $size ? $size : $upload['size'][$index], $upload['type'][$index],
1356
						$upload['name'][$index], $size ? $size : $upload['size'][$index], $upload['type'][$index],
1477
						$upload['error'][$index], $index, $content_range);
1357
						$upload['error'][$index], $index, $content_range);
1478
				}
1358
				}
1479
			} else
1359
			} else {
1480
			{
-
 
1481
				// param_name is a single object identifier like "file",
1360
				// param_name is a single object identifier like "file",
1482
				// $upload is a one-dimensional array:
1361
				// $upload is a one-dimensional array:
1483
				$files[] = $this->handle_file_upload(isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
1362
				$files[] = $this->handle_file_upload(isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
1484
					$file_name ? $file_name : (isset($upload['name']) ? $upload['name'] : null), $size ?
1363
					$file_name ? $file_name : (isset($upload['name']) ? $upload['name'] : null), $size ?
1485
					$size : (isset($upload['size']) ? $upload['size'] : $this->get_server_var('CONTENT_LENGTH')),
1364
					$size : (isset($upload['size']) ? $upload['size'] : $this->get_server_var('CONTENT_LENGTH')),
Zeile 1492... Zeile 1371...
1492
	}
1371
	}
Zeile 1493... Zeile 1372...
1493
 
1372
 
1494
	public function delete($print_response = true)
1373
	public function delete($print_response = true)
1495
	{
1374
	{
1496
		$file_names = $this->get_file_names_params();
1375
		$file_names = $this->get_file_names_params();
1497
		if (empty($file_names))
-
 
1498
		{
1376
		if (empty($file_names)) {
1499
			$file_names = array($this->get_file_name_param());
1377
			$file_names = array($this->get_file_name_param());
1500
		}
1378
		}
1501
		$response = array();
1379
		$response = array();
1502
		foreach ($file_names as $file_name)
-
 
1503
		{
1380
		foreach ($file_names as $file_name) {
1504
			$file_path = $this->get_upload_path($file_name);
1381
			$file_path = $this->get_upload_path($file_name);
1505
			$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
1382
			$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
1506
			if ($success)
-
 
1507
			{
1383
			if ($success) {
1508
				foreach ($this->options['image_versions'] as $version => $options)
-
 
1509
				{
1384
				foreach ($this->options['image_versions'] as $version => $options) {
1510
					if (!empty($version))
-
 
1511
					{
1385
					if (!empty($version)) {
1512
						$file = $this->get_upload_path($file_name, $version);
1386
						$file = $this->get_upload_path($file_name, $version);
1513
						if (is_file($file))
-
 
1514
						{
1387
						if (is_file($file)) {
1515
							unlink($file);
1388
							unlink($file);
1516
						}
1389
						}
1517
					}
1390
					}
1518
				}
1391
				}