图片上传字段为空时出现错误消息

How can make picture upload required on HMS testimonial module?

Here the code bribe about that field :


if (isset($_FILES['hms_testimonials_image']) && ($_FILES['hms_testimonials_image']['size'] > 0) && $settings['form_show_upload'] == 1) {

$get_file_type = wp_check_filetype( basename($_FILES['hms_testimonials_image']['name'] ) );
$uploaded_type = $get_file_type['type'];

if (!in_array($uploaded_type, $allowed))
$errors[] = apply_filters('hms_testimonials_sc_error_image', __('You have uploaded an invalid file type.', 'hms-testimonials') );

}

You can check if no files uploaded using,

count($_FILES);

Above code will return 0 in case user have not uploaded any files.


If there are multiple file upload handling and you want to check for specific filed, You can use is_uploaded_file() to ensure file upload of specific field.

Like this,

if(!is_uploaded_file($_FILES["filed_name"]['tmp_name'])) {
   echo "Error: File not uploaded";
}

http://php.net/manual/en/function.is-uploaded-file.php