Skip to content

Commit e813dc9

Browse files
author
joaoraposo
committed
Fix calculation of bytes read and update database with actual bytes in SendChunk.php
1 parent 689057a commit e813dc9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

trunk/inc/SendChunk.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666

6767
// While the file is not completely read
6868
if (!empty($thisChunk)) {
69+
// Get ACTUAL bytes read (critical fix)
70+
$actual_bytes_read = strlen($thisChunk);
71+
6972
// Prepare the headers
7073
$headers = array(
7174
'content-type' => 'application/binary',
@@ -88,15 +91,15 @@
8891

8992
// Sends the request (creates the chunk file in the UUID folder)
9093
$firstBit = str_pad($inProgress['fileNumber'], 15, '0', STR_PAD_LEFT);
91-
$lastBit = str_pad(($inProgress['fileNumber'] + $memoryFree), 15, '0', STR_PAD_LEFT);
94+
$lastBit = str_pad(($inProgress['fileNumber'] + $actual_bytes_read), 15, '0', STR_PAD_LEFT); // Use actual bytes
9295

9396
$resSendChunk = wp_remote_request(
9497
get_option('hejbit_url_dlwcloud') . '/remote.php/dav/uploads/' . get_option('hejbit_login_dlwcloud') . '/' . $inProgress['uuid'] . "/" . $firstBit . "-" . $lastBit,
9598
$args
9699
);
97100

98-
// Update the database with the new file number
99-
$data = array("fileNumber" => ($inProgress['fileNumber'] + $memoryFree));
101+
// Update the database with ACTUAL bytes read (critical fix)
102+
$data = array("fileNumber" => ($inProgress['fileNumber'] + $actual_bytes_read));
100103
$where = array("finish" => 0);
101104
$wpdb->update($wpdb->prefix . 'hejbit_saveInProgress', $data, $where);
102105

0 commit comments

Comments
 (0)