@@ -270,6 +270,9 @@ public static function uploadFiles($fileslist, $formId)
270
270
$ fileslist = self ::sanitizeFilesList ($ fileslist );
271
271
272
272
foreach ($ fileslist as $ key => $ files ) {
273
+ // Sanitizes the key to the field name (ex. removes id-1-)
274
+ $ sanitizedKey = preg_replace ('/id-\d+-/ ' , '' , $ key );
275
+
273
276
if (!is_array ($ files ['name ' ])) {
274
277
$ files = self ::convertItemToArray ($ files );
275
278
}
@@ -278,31 +281,29 @@ public static function uploadFiles($fileslist, $formId)
278
281
$ fileName = pathinfo ((string )$ files ['name ' ][$ i ], PATHINFO_FILENAME );
279
282
$ fileext = strtolower (pathinfo ((string )$ files ['name ' ][$ i ], PATHINFO_EXTENSION ));
280
283
281
-
282
284
//Validate that image is in correct format
283
- if (in_array ('image/* ' , $ fields [$ key ]['filetypes ' ])) {
284
- $ fields [$ key ]['filetypes ' ] = array_unique (array_merge ($ fields [$ key ]['filetypes ' ], $ allowedImageTypes ));
285
+ if (in_array ('image/* ' , $ fields [$ sanitizedKey ]['filetypes ' ])) {
286
+ $ fields [$ sanitizedKey ]['filetypes ' ] = array_unique (array_merge ($ fields [$ sanitizedKey ]['filetypes ' ], $ allowedImageTypes ));
285
287
}
286
288
287
289
//Validate that video is in correct format
288
- if (in_array ('video/* ' , $ fields [$ key ]['filetypes ' ])) {
289
- $ fields [$ key ]['filetypes ' ] = array_unique (array_merge ($ fields [$ key ]['filetypes ' ], $ allowedVideoTypes ));
290
+ if (in_array ('video/* ' , $ fields [$ sanitizedKey ]['filetypes ' ])) {
291
+ $ fields [$ sanitizedKey ]['filetypes ' ] = array_unique (array_merge ($ fields [$ sanitizedKey ]['filetypes ' ], $ allowedVideoTypes ));
290
292
}
291
293
292
294
293
295
//Not a valid filetype at all
294
- if (!in_array ('. ' . $ fileext , $ fields [$ key ]['filetypes ' ])) {
296
+ if (!in_array ('. ' . $ fileext , $ fields [$ sanitizedKey ]['filetypes ' ])) {
295
297
error_log ('Filetype not allowed ' );
296
298
$ uploaded ['error ' ] = true ;
297
299
$ uploaded ['errorData ' ] = new \WP_Error ('filetype-not-allowed ' , __ ('Filetype not allowed ' , 'modularity-form-builder ' ));
298
300
continue ;
299
301
}
300
302
301
-
302
303
$ encryptionConfigDefined = defined ('ENCRYPT_SECRET_VI ' ) && defined ('ENCRYPT_SECRET_KEY ' ) && defined ('ENCRYPT_METHOD ' );
303
304
304
305
//Encrypt file if encryption is enabled
305
- if (get_option ('options_mod_form_crypt ' ) && empty ($ fields [$ key ]['upload_videos_external ' ]) && $ encryptionConfigDefined ) {
306
+ if (get_option ('options_mod_form_crypt ' ) && empty ($ fields [$ sanitizedKey ]['upload_videos_external ' ]) && $ encryptionConfigDefined ) {
306
307
$ encrypted = file_put_contents (
307
308
$ files ['tmp_name ' ][$ i ],
308
309
\ModularityFormBuilder \App::encryptDecryptFile (
@@ -397,7 +398,7 @@ public static function maybeCreateFolder(string $path): string
397
398
public function getMailDownloadLink ($ filePath )
398
399
{
399
400
//Check if encrypted
400
- if (strpos ($ filePath , sanitize_file_name ("-enc- " . ENCRYPT_METHOD )) !== false ) {
401
+ if (defined ( ' ENCRYPT_METHOD ' ) && strpos ($ filePath , sanitize_file_name ("-enc- " . ENCRYPT_METHOD )) !== false ) {
401
402
return home_url ("/ " ) . '?modFormDownloadEncFilePublic= ' . urlencode (basename ($ filePath )) . '&token= ' . $ this ->createToken ($ filePath );
402
403
}
403
404
0 commit comments