validation for media upload

functions.php


function legal_image_validation($legal_imge_url) {
$legal_filetype = wp_check_filetype($legal_imge_url);
$legal_supported_image = array('pdf','txt','docx','xlsx','gif', 'jpg', 'jpeg', 'png', 'ico');
if (in_array($legal_filetype['ext'], $legal_supported_image)) {
return $legal_imge_url;
} else {
return '';
}
}

Use Function name on when ever like below:


<input id=""  type="text" class=" mytheme_media_url upload" name="documents_image" value="<?php echo legal_image_validation(esc_attr( $documents_image )); ?>" placeholder="No file chosen"  />

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: