Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Admin_Import::validate_upload( array $file )

Validate the uploaded file


Parameters Parameters

$file

(array) (Required) array of file data.


Top ↑

Return Return

(WP_Error|true)


Top ↑

Source Source

File: includes/admin/class.llms.admin.import.php

	private function validate_upload( $file ) {

		if ( ! empty( $file['error'] ) ) {

			switch ( $file['error'] ) {

				case UPLOAD_ERR_INI_SIZE:
					$msg = __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'lifterlms' );
					break;

				case UPLOAD_ERR_FORM_SIZE:
					$msg = __( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', 'lifterlms' );
					break;

				case UPLOAD_ERR_PARTIAL:
					$msg = __( 'The uploaded file was only partially uploaded.', 'lifterlms' );
					break;

				case UPLOAD_ERR_NO_FILE:
					$msg = __( 'No file was uploaded.', 'lifterlms' );
					break;

				case UPLOAD_ERR_NO_TMP_DIR:
					$msg = __( 'Missing a temporary folder.', 'lifterlms' );
					break;

				case UPLOAD_ERR_CANT_WRITE:
					$msg = __( 'Failed to write file to disk.', 'lifterlms' );
					break;

				case UPLOAD_ERR_EXTENSION:
					$msg = __( 'File upload stopped by extension.', 'lifterlms' );
					break;

				default:
					$msg = __( 'Unknown upload error.', 'lifterlms' );

			}
		} else {

			$info = pathinfo( $file['name'] );

			if ( 'json' !== strtolower( $info['extension'] ) ) {
				$msg = __( 'Only valid JSON files can be imported.', 'lifterlms' );
			}
		}

		if ( ! empty( $msg ) ) {
			return new WP_Error( 'llms_import_file_error', $msg );
		}

		return true;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.35.0 Fix undefined variable error.
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.