|
1 | 1 | <?php
|
2 | 2 | /*
|
3 |
| - * jQuery File Upload Plugin PHP Class 6.4.5 |
| 3 | + * jQuery File Upload Plugin PHP Class 6.4.6 |
4 | 4 | * https://github.com/blueimp/jQuery-File-Upload
|
5 | 5 | *
|
6 | 6 | * Copyright 2010, Sebastian Tschan
|
@@ -63,6 +63,9 @@ function __construct($options = null, $initialize = true, $error_messages = null
|
63 | 63 | ),
|
64 | 64 | // Enable to provide file downloads via GET requests to the PHP script:
|
65 | 65 | 'download_via_php' => false,
|
| 66 | + // Read files in chunks to avoid memory limits when download_via_php |
| 67 | + // is enabled, set to 0 to disable chunked reading of files: |
| 68 | + 'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB |
66 | 69 | // Defines which files can be displayed inline when downloaded:
|
67 | 70 | 'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
|
68 | 71 | // Defines which files (based on their names) are accepted for upload:
|
@@ -628,6 +631,18 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
|
628 | 631 | }
|
629 | 632 |
|
630 | 633 | protected function readfile($file_path) {
|
| 634 | + $file_size = $this->get_file_size($file_path); |
| 635 | + $chunk_size = $this->options['readfile_chunk_size']; |
| 636 | + if ($chunk_size && $file_size > $chunk_size) { |
| 637 | + $handle = fopen($file_path, 'rb'); |
| 638 | + while (!feof($handle)) { |
| 639 | + echo fread($handle, $chunk_size); |
| 640 | + ob_flush(); |
| 641 | + flush(); |
| 642 | + } |
| 643 | + fclose($handle); |
| 644 | + return $file_size; |
| 645 | + } |
631 | 646 | return readfile($file_path);
|
632 | 647 | }
|
633 | 648 |
|
|
0 commit comments