function get_dirsize($dirname) { $dirsize = 0; if ($dir = opendir($dirname)) { while ($file = readdir($dir)) { if ($file == "." || $file == "..") { } elseif (is_dir($dirname . '/' . $file)) { $dirsize = $dirsize + get_dirsize($dirname . "/" . $file); } else { $dirsize = $dirsize + filesize($dirname . "/" . $file); } } closedir($dir); } return $dirsize; }
function evc_fetch_remote_file($args) { if (!empty($args)) { extract($args); } //$post_date = date('Y-m-d H:i:s'); $upload = wp_upload_dir(); $upload = wp_upload_bits($file_name, 0, ''); if ($upload['error']) { return new WP_Error('upload_dir_error', $upload['error']); } $headers = wp_get_http($url, $upload['file']); if (!$headers) { @unlink($upload['file']); return new WP_Error('import_file_error', __('Remote server did not respond', 'evc')); } if ($headers['response'] != '200') { @unlink($upload['file']); return new WP_Error('import_file_error', sprintf(__('Remote server says: %1$d %2$s', 'evc'), $headers['response'], get_status_header_desc($headers['response']))); } elseif (isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length']) { @unlink($upload['file']); return new WP_Error('import_file_error', __('Remote file is incorrect size', 'evc')); } $max_size = (int) get_site_option('fileupload_maxk') * 1024; // fileupload_maxk for wpmu compatibility $file_size = filesize($upload['file']); if (!empty($max_size) && $file_size > $max_size) { @unlink($upload['file']); return new WP_Error('import_file_error', sprintf(__('Remote file is %1$d KB but limit is %2$d', 'evc'), $file_size / 1024, $max_size / 1024)); } // This check is for wpmu compatibility if (function_exists('get_space_allowed')) { $space_allowed = 1048576 * get_space_allowed(); $space_used = get_dirsize(BLOGUPLOADDIR); $space_left = $space_allowed - $space_used; if ($space_left < 0) { @unlink($upload['file']); return new WP_Error('not_enough_diskspace', sprintf(__('You have %1$d KB diskspace used but %2$d allowed.', 'evc'), $space_used / 1024, $space_allowed / 1024)); } } $upload['content-type'] = $headers['content-type']; return $upload; }
function wpmu_checkAvailableSpace() { $spaceAllowed = get_space_allowed(); $dirName = trailingslashit(BLOGUPLOADDIR); if (!(is_dir($dirName) && is_readable($dirName))) { return; } $dir = dir($dirName); $size = 0; while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir($dirName . $file)) { $size += get_dirsize($dirName . $file); } else { $size += filesize($dirName . $file); } } } $dir->close(); $size = $size / 1024 / 1024; if ($spaceAllowed - $size <= 0) { define('DISABLE_UPLOADS', true); define('DISABLE_UPLOADS_MESSAGE', __('Sorry, you must delete files before you can upload any more.')); } }
function et_handle_upload_prefilter($file) { if (!is_multisite()) { return $file; } if (get_site_option('upload_space_check_disabled')) { return $file; } if ($file['error'] != '0') { // there's already an error return $file; } if (defined('WP_IMPORTING')) { return $file; } $space_allowed = 1048576 * get_space_allowed(); $space_used = get_dirsize(BLOGUPLOADDIR); $space_left = $space_allowed - $space_used; $file_size = filesize($file['tmp_name']); if ($space_left < $file_size) { $file['error'] = sprintf(__('Not enough space to upload. %1$s KB needed.', ET_DOMAIN), number_format(($file_size - $space_left) / 1024)); } if ($file_size > 1024 * get_site_option('fileupload_maxk', 1500)) { $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.', ET_DOMAIN), get_site_option('fileupload_maxk', 1500)); } if (function_exists('upload_is_user_over_quota') && upload_is_user_over_quota(false)) { $file['error'] = __('You have used your space quota. Please delete files before uploading.', ET_DOMAIN); } // if ( $file['error'] != '0' && !isset($_POST['html-upload']) ) // wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); return $file; }
function rigr_fetch_remote_file($post, $url) { $url2 = str_replace('&', '&', str_replace('https://', 'http://', $url)); preg_match('/[a-z0-9;=_%\\Q?&.-+[]\\E]+\\.(jpg|jpeg|gif|png|rar|zip|mp3|mp4|flv|pdf|swf)/i', $url2, $pu); $file_name = str_replace('%25', '-', $pu[0]); $file_name = preg_replace('/[;=%\\Q?&-+\\E]+/i', '-', $file_name); $file_name = strlen($file_name) > 255 ? substr($file_name, 180) : $file_name; $upload = wp_upload_bits($file_name, 0, '', $post['post_date']); if ($upload['error']) { echo $upload['error']; return new WP_Error('upload_dir_error', $upload['error']); } $headers = wp_get_http($url2, $upload['file']); if (!$headers) { @unlink($upload['file']); return new WP_Error('import_file_error', __('<p class="help"><img src="images/no.png"> <span style="color: #ff0000;">Remote server did not respond</span></p>', 'rigr')); } if ($headers['response'] != '200') { @unlink($upload['file']); return new WP_Error('import_file_error', sprintf(__('Remote server says: %1$d %2$s', 'rigr'), $headers['response'], get_status_header_desc($headers['response']))); } elseif (isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length']) { @unlink($upload['file']); return new WP_Error('import_file_error', __('<p class="help"><img src="images/no.png"> <span style="color: #ff0000;">Remote file can not be downloaded</span></p>', 'rigr')); } $min_size = max((double) $_POST['rigr_min_size'], 0) * 1024; $max_size = max((int) $_POST['rigr_max_size'], (int) get_site_option('fileupload_maxk')) * 1024; /* -- fileupload_maxk for wpmu compatibility -- */ $file_size = filesize($upload['file']); if (!empty($max_size) && $file_size > $max_size) { @unlink($upload['file']); return new WP_Error('import_file_error', sprintf(__('Remote file is %1$d KB but limit is %2$d', 'rigr'), $file_size / 1024, $max_size / 1024)); } elseif (!empty($min_size) && $file_size < $min_size) { @unlink($upload['file']); return new WP_Error('import_file_error', sprintf(__('Remote file size is less then %1$d KB', 'rigr'), $min_size / 1024)); } /* -- This check is for wpmu compatibility -- */ if (function_exists('get_space_allowed')) { $space_allowed = 1048576 * get_space_allowed(); $space_used = get_dirsize(BLOGUPLOADDIR); $space_left = $space_allowed - $space_used; if ($space_left < 0) { @unlink($upload['file']); return new WP_Error('not_enough_diskspace', sprintf(__('You have %1$d KB diskspace used but %2$d allowed.', 'rigr'), $space_used / 1024, $space_allowed / 1024)); } } $upload['content-type'] = $headers['content-type']; return $upload; }
function details() { // take default seetings $settings = array('remain' => array('color_text' => 'white', 'color_bar' => '#0D324F', 'color_bg' => '#a0a0a0', 'decimals' => 2, 'unit' => 'm', 'display' => true, 'graph' => false), 'used' => array('color_text' => 'white', 'color_bar' => '#0D324F', 'color_bg' => '#a0a0a0', 'decimals' => 2, 'unit' => 'm', 'display' => true, 'graph' => true)); $quota = ngg_SpaceManager::getQuota() * 1024 * 1024; $used = get_dirsize(constant("ABSPATH") . constant("UPLOADS")); // $used = get_dirsize( ABSPATH."wp-content/blogs.dir/".$blog_id."/files" ); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $remaining = $quota - $used; $percentremain = 100 - $percentused; $out = ""; $out .= '<div id="spaceused"> <h3>' . __('Storage Space', 'nggallery') . '</h3>'; if ($settings['used']['display']) { $out .= __('Upload Space Used:', 'nggallery') . "\n"; $out .= ngg_SpaceManager::buildGraph($settings['used'], $used, $quota, $percentused); $out .= "<br />"; } if ($settings['remain']['display']) { $out .= __('Upload Space Remaining:', 'nggallery') . "\n"; $out .= ngg_SpaceManager::buildGraph($settings['remain'], $remaining, $quota, $percentremain); } $out .= "</div>"; echo $out; }
function wp_dashboard_quota() { if (!is_multisite() || !current_user_can('upload_files') || get_site_option('upload_space_check_disabled')) { return true; } $quota = get_space_allowed(); $used = get_dirsize(BLOGUPLOADDIR) / 1024 / 1024; if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_color = $percentused >= 70 ? ' spam' : ''; $used = round($used, 2); $percentused = number_format($percentused); ?> <p class="sub musub"><?php _e('Storage Space'); ?> </p> <div class="table table_content musubtable"> <table> <tr class="first"> <td class="first b b-posts"><?php printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>'), esc_url(admin_url('upload.php')), $quota); ?> </td> <td class="t posts"><?php _e('Space Allowed'); ?> </td> </tr> </table> </div> <div class="table table_discussion musubtable"> <table> <tr class="first"> <td class="b b-comments"><?php printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>'), esc_url(admin_url('upload.php')), $used, $percentused); ?> </td> <td class="last t comments<?php echo $used_color; ?> "><?php _e('Space Used'); ?> </td> </tr> </table> </div> <br class="clear" /> <?php }
/** * Returns the space used by the current blog. * * @since 3.5.0 * * @return int Used space in megabytes */ function get_space_used() { /** * Filter the amount of storage space used by the current site. * * @since 3.5.0 * * @param int|bool $space_used The amount of used space, in megabytes. Default false. */ $space_used = apply_filters('pre_get_space_used', false); if (false === $space_used) { $upload_dir = wp_upload_dir(); $space_used = get_dirsize($upload_dir['basedir']) / 1024 / 1024; } return $space_used; }
function wpmu_checkAvailableSpace() { if (get_site_option('upload_space_check_disabled')) { return true; } $spaceAllowed = get_space_allowed(); $dirName = trailingslashit(BLOGUPLOADDIR); if (!(is_dir($dirName) && is_readable($dirName))) { return; } $dir = dir($dirName); $size = 0; while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir($dirName . $file)) { $size += get_dirsize($dirName . $file); } else { $size += filesize($dirName . $file); } } } $dir->close(); $size = $size / 1024 / 1024; if ($spaceAllowed - $size <= 0) { wp_die(__('Sorry, you must delete files before you can upload any more.')); } }
/** * Get the available disk space for this account. */ function cpm_wpmu_get_available_disk_space() { $space_allowed = 1048576 * get_space_allowed(); $space_used = get_dirsize(constant("ABSPATH") . constant("UPLOADS")); return $space_allowed - $space_used; }
/** * Get the remaining upload space for this blog. * * @since MU * @uses upload_is_user_over_quota() * @uses get_space_allowed() * @uses get_dirsize() * * @param int $size * @return int */ function fix_import_form_size( $size ) { if ( upload_is_user_over_quota( false ) == true ) return 0; $spaceAllowed = 1024 * 1024 * get_space_allowed(); $dirsize = get_dirsize( BLOGUPLOADDIR ); if ( $size > $spaceAllowed - $dirsize ) return $spaceAllowed - $dirsize; // remaining space else return $size; // default }
/** * Returns the space used by the current blog. * * @since 3.5.0 * * @return int Used space in megabytes */ function get_space_used() { // Allow for an alternative way of tracking storage space used $space_used = apply_filters('pre_get_space_used', false); if (false === $space_used) { $space_used = get_dirsize(BLOGUPLOADDIR) / 1024 / 1024; } return $space_used; }
function _get_space() { $space = get_space_allowed(); //echo "space<pre>"; print_r($space); echo "</pre>"; $_used_bytes = apply_filters('embi_upload_storage_used_bytes', get_dirsize(BLOGUPLOADDIR)); $used = apply_filters('embi_upload_storage_used_mb', $_used_bytes / 1024 / 1024); $available = $space - $used; $percentused = sprintf("%.2f", $used / $space * 100); $space = $space > 1000 ? sprintf("%.2f", $space / 1024) . __('GB') : sprintf("%.2f", $space) . __('MB'); $used = $used > 1000 ? sprintf("%.2f", $used / 1024) . __('GB') : sprintf("%.2f", $used) . __('MB'); $available = $available > 1000 ? sprintf("%.2f", $available / 1024) . __('GB') : sprintf("%.2f", $available) . __('MB'); return array('total' => $space, 'used' => $used, 'percent' => $percentused, 'available' => $available); }
function dashboard_quota() { if (get_site_option('upload_space_check_disabled')) { return; } if (!wpmu_enable_function('wpmuQuotaCheck')) { return; } $settings = C_NextGen_Settings::get_instance(); $fs = C_Fs::get_instance(); $dir = $fs->join_paths($fs->get_document_root('content'), $settings->gallerypath); $quota = get_space_allowed(); $used = get_dirsize($dir) / 1024 / 1024; if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_color = $percentused < 70 ? $percentused >= 40 ? 'yellow' : 'green' : 'red'; $used = round($used, 2); $percentused = number_format($percentused); ?> <p><?php print __('Storage Space'); ?> </p> <ul> <li><?php printf(__('%1$sMB Allowed', 'nggallery'), $quota); ?> </li> <li class="<?php print $used_color; ?> "><?php printf(__('%1$sMB (%2$s%%) Used', 'nggallery'), $used, $percentused); ?> </li> </ul> <?php }
function ngg_dashboard_quota() { if (get_site_option('upload_space_check_disabled')) { return; } if (!wpmu_enable_function('wpmuQuotaCheck')) { return; } $quota = get_space_allowed(); $used = get_dirsize(BLOGUPLOADDIR) / 1024 / 1024; if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_color = $percentused < 70 ? $percentused >= 40 ? 'waiting' : 'approved' : 'spam'; $used = round($used, 2); $percentused = number_format($percentused); ?> <p class="sub musub" style="position:static" ><?php _e('Storage Space'); ?> </p> <div class="table table_content musubtable"> <table> <tr class="first"> <td class="first b b-posts"><?php printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>'), esc_url(admin_url('admin.php?page=nggallery-manage-gallery')), $quota); ?> </td> <td class="t posts"><?php _e('Space Allowed'); ?> </td> </tr> </table> </div> <div class="table table_discussion musubtable"> <table> <tr class="first"> <td class="b b-comments"><?php printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>'), esc_url(admin_url('admin.php?page=nggallery-manage-gallery')), $used, $percentused); ?> </td> <td class="last t comments <?php echo $used_color; ?> "><?php _e('Space Used'); ?> </td> </tr> </table> </div> <br class="clear" /> <?php }
function dashboard_quota() { if ( get_site_option( 'upload_space_check_disabled' ) ) return true; $quota = get_space_allowed(); $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024; if ( $used > $quota ) $percentused = '100'; else $percentused = ( $used / $quota ) * 100; $used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam'; $used = round( $used, 2 ); $percentused = number_format( $percentused ); ?> <p class="sub musub"><?php _e( 'Storage Space' ); ?></p> <div class="table table_content musubtable"> <table> <tr class="first"> <td class="first b b-posts"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>' ), esc_url( admin_url( 'upload.php' ) ), $quota ); ?></td> <td class="t posts"><?php _e( 'Space Allowed' ); ?></td> </tr> </table> </div> <div class="table table_discussion musubtable"> <table> <tr class="first"> <td class="b b-comments"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>' ), esc_url( admin_url( 'upload.php' ) ), $used, $percentused ); ?></td> <td class="last t comments <?php echo $used_color;?>"><?php _e( 'Space Used' );?></td> </tr> </table> </div> <br class="clear" /> <?php }
/** * Calculate the Used space by a component * * @see mpp_get_used_space * * @access private do not call it directly, use mpp_get_used_space instead * * @param type $component * @param type $component_id * @return int */ public function get_used_space($component, $component_id) { //let us check for the transient as space calculation is bad everytime $key = "mpp_space_used_by_{$component}_{$component_id}"; //transient key $used_space = get_transient($key); if (!$used_space) { $dir_name = trailingslashit($this->get_component_base_dir($component, $component_id)); //base gallery directory for owner if (!is_dir($dir_name) || !is_readable($dir_name)) { return 0; //we don't know the usage or no usage } $dir = dir($dir_name); $size = 0; while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir($dir_name . $file)) { $size += get_dirsize($dir_name . $file); } else { $size += filesize($dir_name . $file); } } } $dir->close(); set_transient($key, $size, DAY_IN_SECONDS); $used_space = $size; } $used_space = $used_space / 1024 / 1024; return $used_space; }
function fix_import_form_size($size) { if (upload_is_user_over_quota(false) == true) { return 0; } $spaceAllowed = 1024 * 1024 * get_space_allowed(); $dirName = constant("ABSPATH") . constant("UPLOADS"); $dirsize = get_dirsize($dirName); if ($size > $spaceAllowed - $dirsize) { return $spaceAllowed - $dirsize; // remaining space } else { return $size; // default } }
/** * Used to give a realistic total of storage space used on a Multisite subsite, * when there have been attachments uploaded to S3 but removed from server * * @param $space_used bool * * @return float|int */ function multisite_get_spaced_used($space_used) { global $wpdb; // Sum the total file size (including image sizes) for all S3 attachments $sql = "SELECT SUM( meta_value ) AS bytes_total\n\t\t\t\tFROM {$wpdb->postmeta}\n\t\t\t\tWHERE meta_key = 'wpos3_filesize_total'"; $space_used = $wpdb->get_var($sql); // Get local upload sizes $upload_dir = wp_upload_dir(); $space_used += get_dirsize($upload_dir['basedir']); if ($space_used > 0) { // Convert to bytes to MB $space_used = $space_used / 1024 / 1024; } return $space_used; }
/** * Returns the space used by the current blog. * * @since 3.5.0 * * @return int Used space in megabytes */ function get_space_used() { // Allow for an alternative way of tracking storage space used $space_used = apply_filters('pre_get_space_used', false); if (false === $space_used) { $upload_dir = wp_upload_dir(); $space_used = get_dirsize($upload_dir['basedir']) / 1024 / 1024; } return $space_used; }
function display_space_usage() { $space = get_space_allowed(); $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024; $percentused = ( $used / $space ) * 100; if ( $space > 1000 ) { $space = number_format( $space / 1024 ); /* translators: Gigabytes */ $space .= __( 'GB' ); } else { /* translators: Megabytes */ $space .= __( 'MB' ); } ?> <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percentused ), $space ); ?></strong> <?php }
_e('Storage Space Full!', 'catablog'); ?> </h2> <?php $this->render_catablog_admin_message(); ?> <p> <?php _e("CataBlog can't make a new entry because your site has run out of storage space.", 'catablog'); ?> </p> <p> <?php $current_usage = round(get_dirsize(BLOGUPLOADDIR) / 1024 / 1024, 2); ?> <?php sprintf(_e('You are currently using %sMB of %sMB of storage space.', 'catablog'), $current_usage, get_space_allowed()); ?> </p> <p> <?php _e('Please talk to your WordPress Administrator to have more space allocated to your site or delete some previous uploaded content.', 'catablog'); ?> </p> <ul> <li><strong><?php _e('Go To:', 'catablog'); ?> </strong></li>
/** * Get the remaining upload space for this blog. * * @since MU * @uses upload_is_user_over_quota() * @uses get_space_allowed() * @uses get_dirsize() * * @param int $size * @return int */ function fix_import_form_size($size) { if (upload_is_user_over_quota(false) == true) { return 0; } $spaceAllowed = 1024 * 1024 * get_space_allowed(); $dirName = BLOGUPLOADDIR; $dirsize = get_dirsize($dirName); if ($size > $spaceAllowed - $dirsize) { return $spaceAllowed - $dirsize; } else { return $size; } // default }
public function upload_space_used($b_id) { $dirName = WP_CONTENT_DIR . '/blogs.dir/' . $b_id . '/'; if ($b_id == 1) { $dirName = WP_CONTENT_DIR . '/uploads/'; } echo '<strong>' . round(get_dirsize($dirName) / 1024 / 1024, 2) . '</strong> MB'; }