Upload::format_multiple_files( array $file_post )

Description #

Format $_FILES field which have multiple files.

Parameters #

  • $file_post
    array (Required) single $_FILE field.

Source #

File: lib/form/class-upload.php

	private function format_multiple_files( $file_post ) {
		if ( ! is_array( $file_post['name'] ) ) {
			return $file_post;
		}

		$file_ary   = array();
		$file_count = count( $file_post['name'] );
		$file_keys  = array_keys( $file_post );

		for ( $i = 0; $i < $file_count; $i++ ) {
			foreach ( $file_keys as $key ) {
				$file_ary[ $i ][ $key ] = $file_post[ $key ][ $i ];
			}
		}

		return array_filter(
			$file_ary,
			function ( $a ) {
				return ! empty( $a['name'] );
			}
		);
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment