Skip to content

Instantly share code, notes, and snippets.

@stevenspads
Created July 19, 2016 16:44
Show Gist options
  • Save stevenspads/410706d076a6dbe6d5fd5cdc5871be65 to your computer and use it in GitHub Desktop.
Save stevenspads/410706d076a6dbe6d5fd5cdc5871be65 to your computer and use it in GitHub Desktop.
$errors = array();
if(isset($_FILES))
{
foreach($_FILES as $file)
{
if($file['error'] == 0)
{
$file_type = wp_check_filetype(basename($file['name']));
$uploaded_file_type = $file_type['type'];
$allowed_file_types = array('image/jpg','image/jpeg','image/png');
if(! in_array($uploaded_file_type, $allowed_file_types))
{
$errors[count($errors)] = __('Please upload JPEG or PNG file types only', TXT_DOMAIN);
break;
}
}
else if($file['error'] == 1 || $file['error'] == 2)
{
$errors[count($errors)] = __('File sizes must be less than ...');
break;
}
else if($file['error'] == 3)
{
$errors[count($errors)] = __('An uploaded file was only partially loaded');
break;
}
else if($file['error'] == 6)
{
$errors[count($errors)] = __('File upload is missing a temporary folder');
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment