Skip to content

Commit

Permalink
use stream_copy_to_stream (prasathmani#1014)
Browse files Browse the repository at this point in the history
* use stream_copy_to_stream

it's simpler, and should be faster.
For example, stream_copy_to_stream can use sendfile ( https://man7.org/linux/man-pages/man2/sendfile.2.html ) on operating systems supporting it, which is faster and use less RAM than fread()+fwrite() (because it avoids copying data to/from userland, doing the copy entirely in-kernel~)

* fix loop early return, and workaround bug

* use feof

ref prasathmani#1016 (comment)
  • Loading branch information
divinity76 authored and ner00 committed May 7, 2023
1 parent db3191c commit 637183c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,12 @@ function get_file_path () {
if ($out) {
$in = @fopen($tmp_name, "rb");
if ($in) {
while ($buff = fread($in, 4096)) { fwrite($out, $buff); }
if (PHP_VERSION_ID < 80009) {
// workaround https://bugs.php.net/bug.php?id=81145
while (!feof($in)) { fwrite($out, fread($in, 4096)); }
} else {
stream_copy_to_stream($in, $out);
}
$response = array (
'status' => 'success',
'info' => "file upload successful"
Expand Down

0 comments on commit 637183c

Please sign in to comment.