Skip to content

Commit 2d5672e

Browse files
Revert "fix: combine the chunks"
This reverts commit e8fbd44.
1 parent e8fbd44 commit 2d5672e

File tree

1 file changed

+2
-42
lines changed

1 file changed

+2
-42
lines changed

inc/files.php

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,9 @@ function ppom_upload_file() {
205205
$file_path_thumb = $file_dir_path . 'thumbs';
206206
$file_name = wp_unique_filename( $file_path_thumb, $file_name );
207207
$file_name = strtolower( $file_name );
208-
$original_name = $file_name;
209208
$file_ext = pathinfo( $file_name, PATHINFO_EXTENSION );
210-
$original_name = str_replace(".$file_ext", "", $original_name);
211209
$unique_hash = substr( hash( 'sha256', wp_generate_password( 8, false, false ) ), 0, 8 );
212-
$file_name = str_replace( ".$file_ext", "." . $chunk . ".$unique_hash.$file_ext", $file_name );
210+
$file_name = str_replace( ".$file_ext", ".$unique_hash.$file_ext", $file_name );
213211
$file_path = $file_dir_path . $file_name;
214212

215213
// Make sure the fileName is unique but only if chunking is disabled
@@ -301,45 +299,7 @@ function ppom_upload_file() {
301299
}
302300

303301
// Check if file has been uploaded
304-
if ( ! $chunks || $chunk === $chunks - 1 ) {
305-
306-
// Gather all the chunks and combine them into a single file.
307-
$final_file = fopen($file_path, 'wb');
308-
if ( $final_file ) {
309-
$chunks_files_path = [];
310-
$dir = opendir($file_dir_path);
311-
if ($dir) {
312-
while (($file = readdir($dir)) !== false) {
313-
$tmpfilePath = $file_dir_path . $file;
314-
315-
if ( false !== strpos($tmpfilePath, $original_name) && false !== strpos($tmpfilePath, '.part')) {
316-
$chunks_files_path[] = $tmpfilePath;
317-
}
318-
}
319-
closedir($dir);
320-
}
321-
322-
sort( $chunks_files_path );
323-
324-
foreach( $chunks_files_path as $tmpfilePath ) {
325-
$chunk_file = fopen($tmpfilePath, 'rb');
326-
if ($chunk_file) {
327-
while ($buffer = fread($chunk_file, 4096)) {
328-
fwrite($final_file, $buffer);
329-
}
330-
fclose($chunk_file);
331-
// Optionally, you can delete the chunk file after appending it to the final file
332-
unlink($tmpfilePath);
333-
} else {
334-
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to open chunk file."}, "id" : "id"}');
335-
}
336-
}
337-
338-
fclose($final_file);
339-
} else {
340-
die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "Failed to open final file."}, "id" : "id"}');
341-
}
342-
302+
if ( ! $chunks || $chunk == $chunks - 1 ) {
343303
// Strip the temp .part suffix off
344304
rename( "{$file_path}.part", $file_path );
345305

0 commit comments

Comments
 (0)