/** * Checks file uploaded size upon user's space left and max upload size * * @deprecated 1.3.0 * * @param array $file $_FILE array * @uses buddydrive_get_user_space_left() to get user's space left * @uses buddydrive_max_upload_size() to get max upload size * @return array $file the $_FILE array with an eventual error */ function buddydrive_check_upload_size($file) { // there's already an error if (!empty($file['error'])) { return $file; } // This codes are restricted to BuddyDrive $buddydrive_errors = array(9 => 1, 10 => 1, 11 => 1); // what's left in user's quota ? $space_left = buddydrive_get_user_space_left('diff'); $file_size = filesize($file['tmp_name']); // File is bigger than space left if ($space_left < $file_size) { $file['error'] = 9; } // File is bigger than the max allowed for BuddyDrive files if ($file_size > buddydrive_max_upload_size(true)) { $file['error'] = 10; } // No more space left if ($space_left <= 0) { $file['error'] = 11; } if (!isset($buddydrive_errors[$file['error']])) { return apply_filters('buddydrive_upload_errors', $file); } return $file; }
/** * Returns an array of upload errors * * @since 1.2.2 * * Takes WordPress ones + BuddyDrive ones index 9 to 11 * @uses apply_filters call 'buddydrive_get_upload_error_strings' to add custom errors * You'll need to start at index 12. * @return array list of BuddyDrive errors */ function buddydrive_get_upload_error_strings() { $custom_errors = apply_filters('buddydrive_get_upload_error_strings', array()); $upload_errors = array(9 => __('Not enough space left to upload your file', 'buddydrive'), 10 => sprintf(__('This file is too big. Files must be less than %s MB in size.', 'buddydrive'), buddydrive_max_upload_size()), 11 => __('You have used your space quota. Please delete files before uploading.', 'buddydrive')); if (!empty($custom_errors) && !array_intersect_key($upload_errors, $custom_errors)) { foreach ($custom_errors as $key_error => $error_message) { // Custom errors need to start at 12 index. if ($key_error < 12) { continue; } $upload_errors[$key_error] = $error_message; } } return $upload_errors; }
/** * Let the admin customize the max upload size as long as it's less than its config can ! * * @uses buddydrive_max_upload_size() to get the max upload size choosed * @return string html */ function buddydrive_admin_setting_callback_max_upload() { $buddydrive_upload = buddydrive_max_upload_size(); ?> <input name="_buddydrive_max_upload" type="number" min="1" step="1" id="_buddydrive_max_upload" value="<?php echo $buddydrive_upload; ?> " class="small-text" /> <label for="_buddydrive_max_upload"><?php _e('MO', 'buddydrive'); ?> </label> <?php }