@@ -205,11 +205,9 @@ function ppom_upload_file() {
205
205
$ file_path_thumb = $ file_dir_path . 'thumbs ' ;
206
206
$ file_name = wp_unique_filename ( $ file_path_thumb , $ file_name );
207
207
$ file_name = strtolower ( $ file_name );
208
- $ original_name = $ file_name ;
209
208
$ file_ext = pathinfo ( $ file_name , PATHINFO_EXTENSION );
210
- $ original_name = str_replace (". $ file_ext " , "" , $ original_name );
211
209
$ 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 );
213
211
$ file_path = $ file_dir_path . $ file_name ;
214
212
215
213
// Make sure the fileName is unique but only if chunking is disabled
@@ -301,45 +299,7 @@ function ppom_upload_file() {
301
299
}
302
300
303
301
// 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 ) {
343
303
// Strip the temp .part suffix off
344
304
rename ( "{$ file_path }.part " , $ file_path );
345
305
0 commit comments