/** * Determine the maximum file upload size by querying the PHP settings. * * @return * A file size limit in bytes based on the PHP upload_max_filesize and * post_max_size */ function file_upload_max_size() { static $max_size; if (isset($max_size)) { return $max_size; } $upload_max = parse_size(ini_get('upload_max_filesize')); $post_max = parse_size(ini_get('post_max_size')); $max_size = min($upload_max, $post_max); return $max_size; }
function file_upload_max_size() { static $max_size = -1; if ($max_size < 0) { $max_size = parse_size(ini_get('post_max_size')); $upload_max = parse_size(ini_get('upload_max_filesize')); if ($upload_max > 0 && $upload_max < $max_size) { $max_size = $upload_max; } } return $max_size; }
function file_upload_max_size() { static $max_size = -1; if ($max_size < 0) { // Start with post_max_size. $max_size = parse_size(ini_get('post_max_size')); // If upload_max_size is less, then reduce. Except if upload_max_size is // zero, which indicates no limit. $upload_max = parse_size(ini_get('upload_max_filesize')); if ($upload_max > 0 && $upload_max < $max_size) { $max_size = $upload_max; } } return $max_size; }
/** function used to get the numeration of entites * return array $entitynum - numertaion of entities */ function get_maxloadsize() { require_once 'include/utils/UserInfoUtil.php'; require_once 'modules/Users/Users.php'; global $adb, $log, $current_user; $log->debug("Entering vtws_get_maxloadsize ()"); $max_size = parse_size(ini_get('post_max_size')); // If upload_max_size is less, then reduce. Except if upload_max_size is // zero, which indicates no limit. $upload_max = parse_size(ini_get('upload_max_filesize')); if ($upload_max > 0 && $upload_max < $max_size) { $max_size = $upload_max; } $log->debug("Exiting get_maxloadsize"); return $max_size; }
function show_file($file_name) { global $newPath, $BASE_DIR, $BASE_URL, $FILE_ROOT; $size = filesize($BASE_DIR . $FILE_ROOT . $file_name); $ext = getExtension($BASE_DIR . $FILE_ROOT . $file_name); if (!is_file(getcwd() . "/icons/" . $ext . ".gif")) { $ext = "def"; } ?> <td> <table width="102" border="0" cellpadding="0" cellspacing="2"> <tr> <td align="center" class="imgBorder" onMouseOver="pviiClassNew(this,'imgBorderHover')" onMouseOut="pviiClassNew(this,'imgBorder')"> <a href="javascript:;" onClick="fileSelected('<?php echo $newPath . "/" . $file_name; ?> ','<?php echo $file_name . " (" . parse_size($size) . ")"; ?> ')"> <img src="icons/<?php echo $ext; ?> .gif" width="48" height="48" border=0 alt="<?php echo $file_name . " (" . parse_size($size) . ")"; ?> "> </a> </td> </tr> <tr> <td><table width="100%" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="1%" class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <a href="files.php?delFile=<?php echo $file_name; ?> &dir=<?php echo $newPath; ?> " onClick="return deleteFile('<?php echo $file_name; ?> ');"><img src="images/edit_trash.gif" width="15" height="15" border="0" alt="Delete this file"></a></td> <td width="99%" class="imgCaption"><?php echo $file_name; ?> </td> </tr> </table></td> </tr> </table> </td> <?php }
/* get max. file size from php.ini configuration */ function parse_size($size) { $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. $size = preg_replace('/[^0-9\\.]/', '', $size); // Remove the non-numeric characters from the size. if ($unit) { // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); } else { return round($size); } } $maxFileSize = parse_size(ini_get('post_max_size')) < parse_size(ini_get('upload_max_filesize')) ? ini_get('post_max_size') : ini_get('upload_max_filesize'); try { //if file exceeded the filesize, no file will be sent if (!isset($_FILES['uploadedFile'])) { throw new RuntimeException("No file sent, you must upload a (.axp) file not greater than {$maxFileSize}"); } $file = pathinfo($_FILES['uploadedFile']['name']); $ext = $file['extension']; // get the extension of the file $filename = $file['filename']; // Undefined | Multiple Files | $_FILES Corruption Attack // If this request falls under any of them, treat it invalid. // Check $_FILES['uploadedFile']['error'] value. switch ($_FILES['uploadedFile']['error']) { case UPLOAD_ERR_OK: break;
$size = 0; $size = @ini_get('upload_max_filesize'); if ($size) { $size = parse_size($size); } if ($size > 0) { $ts = @ini_get('post_max_size'); if ($ts) { $ts = parse_size($size); } if ($ts > 0) { $size = min($size, $ts); } $ts = @ini_get('memory_limit'); if ($ts) { $ts = parse_size($size); } if ($ts > 0) { $size = min($size, $ts); } } if (empty($size)) { $size = ''; } else { $size = sizecount($size); } $info['limit'] = $size; $sql = 'SELECT VERSION();'; $info['mysql']['version'] = pdo_fetchcolumn($sql); $tables = pdo_fetchall("SHOW TABLE STATUS LIKE '" . $_W['config']['db']['tablepre'] . "%'"); $size = 0;
<p class="notebox"> <?php echo gettext('<strong>Note: </strong>'); ?> <br /> <?php if ($last == 'ZIP') { echo gettext('ZIP files must contain only supported <em>image</em> types.'); ?> <br /> <?php } $maxupload = ini_get('upload_max_filesize'); $maxpost = ini_get('post_max_size'); $maxuploadint = parse_size($maxupload); $maxpostint = parse_size($maxpost); if ($maxuploadint < $maxpostint) { echo sprintf(gettext("The maximum size for any one file is <strong>%sB</strong> and the maximum size for one total upload is <strong>%sB</strong> which are set by your PHP configuration <code>upload_max_filesize</code> and <code>post_max_size</code>."), $maxupload, $maxpost); } else { echo ' ' . sprintf(gettext("The maximum size for your total upload is <strong>%sB</strong> which is set by your PHP configuration <code>post_max_size</code>."), $maxpost); } $uploadlimit = zp_apply_filter('get_upload_limit', $maxuploadint); $maxuploadint = min($maxuploadint, $uploadlimit); ?> <br /> <?php echo zp_apply_filter('get_upload_header_text', gettext('Don’t forget, you can also use <acronym title="File Transfer Protocol">FTP</acronym> to upload folders of images into the albums directory!')); ?> </p> <?php if (isset($_GET['error'])) {
function get_byte($raw) { // $raw : '500kb', '1mb' require_once 'lib/byte_converter.class.php'; $file_raw_size = parse_size($raw); $size_in_byte = 0; try { $byte = new byte_converter(); $byte->set_limit("tb"); //show types up to tera byte $file_size = $byte->auto($file_raw_size[0], $file_raw_size[1]); $size_in_byte = $file_size['b']; } catch (Exception $e) { echo $e; } return $size_in_byte; }
function show_image($img, $file, $info, $size, $listdir, $i) { $img_file = basename($img); $img_url_link = _FPSSLIVESITE . $listdir . "/" . rawurlencode($img_file); $filesize = parse_size($size); if ($info[0] > 120 || $info[0] > 120) { $img_dimensions = imageResize($info[0], $info[1], 120); } else { $img_dimensions = 'width="' . $info[0] . '" height="' . $info[1] . '"'; } ?> <tr> <td><img id="image<?php echo $i; ?> " onmouseover="this.style.cursor='pointer'" onclick="javascript:sendtomain(<?php echo $i; ?> );" src="<?php echo $img_url_link; ?> " <?php echo $img_dimensions; ?> border="0" /></td> <td><b><?php echo htmlspecialchars(substr($file, 0, 20) . (strlen($file) > 20 ? '...' : ''), ENT_QUOTES); ?> </b></td> <td><b class="red"><?php echo $info[0]; ?> x<?php echo $info[1]; ?> px</b></td> <td><?php echo $filesize; ?> </td> </tr> <?php }
protected function getValidators() { $extensions = array(); $types = file_type_get_enabled_types(); foreach ($types as $t => $type) { $extensions = array_merge($extensions, _os_files_extensions_from_type($t)); } $validators = array('file_validate_extensions' => array(implode(' ', $extensions)), 'file_validate_size' => array(parse_size(file_upload_max_size()))); return $validators; }
function show_image($img, $file, $info, $size) { global $BASE_DIR, $BASE_URL, $newPath; $img_path = dir_name($img); $img_file = basename($img); $thumb_image = 'thumbs.php?img=' . urlencode($img); $img_url = $BASE_URL . $img_path . '/' . $img_file; $filesize = parse_size($size); ?> <td> <table width="102" border="0" cellpadding="0" cellspacing="2"> <tr> <td align="center" class="imgBorder" onMouseOver="pviiClassNew(this,'imgBorderHover')" onMouseOut="pviiClassNew(this,'imgBorder')"> <a href="javascript:;" onClick="javascript:imageSelected('<?php echo $img_url; ?> ', <?php echo $info[0]; ?> , <?php echo $info[1]; ?> ,'<?php echo $file; ?> ');"><img src="<?php echo $thumb_image; ?> " alt="<?php echo $file; ?> - <?php echo $filesize; ?> " border="0"></a></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="1%" class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <a href="javascript:;" onClick="javascript:preview('<?php echo $img_url; ?> ', '<?php echo $file; ?> ', ' <?php echo $filesize; ?> ',<?php echo $info[0] . ',' . $info[1]; ?> );"><img src="edit_pencil.gif" width="15" height="15" border="0"></a></td> <td width="1%" class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <a href="images.php?delFile=<?php echo $img_url; ?> &dir=<?php echo $newPath; ?> " onClick="return deleteImage('<?php echo $file; ?> ');"><img src="edit_trash.gif" width="15" height="15" border="0"></a></td> <td width="98%" class="imgCaption"><?php echo $info[0] . 'x' . $info[1]; ?> </td> </tr> </table></td> </tr> </table> </td> <?php }
<td width="0px" style="display: none;"> </td> <td width="0px" style="display: none;">' . $time . '</td> </tr>'; $folderJSArray .= "['img/ext/folder_small.gif', '" . sanitize($entry) . "', '" . _filemanager_folder . "', '" . $parsed_time . "'],\n"; $folderNb++; } else { $entries_cnt++; $ext = substr(strrchr($entry, '.'), 1); if (is_array($MY_LIST_EXTENSIONS)) { if (!in_array(strtolower($ext), $MY_LIST_EXTENSIONS)) { continue; } } $size = filesize($absolutePath); $time = filemtime($absolutePath); $parsed_size = parse_size($size); $parsed_time = parse_time($time); $parsed_icon = 'img/ext/' . parse_icon($ext); $css_class = $ext . '_bg'; #need to take img out and replace by css style # <td width="4%"><img src="'.$parsed_icon.'" width="16" height="16" border="0" alt="'.$entry.'" /></td> $t_files .= '<tr id="F' . $fileNb++ . '"> <td width="50%"><div style="height:15px; overflow:hidden;" ><a class="' . $css_class . '" href="javascript:;" onClick="javascript:fileSelected(\'' . $MY_BASE_URL . $relativePath . '\',\'' . $entry . '\',\'' . $parsed_icon . '\',\'' . $parsed_size . '\',\'' . $parsed_time . '\');">' . $entry . '</div></td> <td width="18%" align="right">' . $parsed_size . '</td> <td width="25%">' . $parsed_time . '</td> <td width="0px" style="display: none;">' . $ext . '</td> <td width="0px" style="display: none;">' . $size . '</td> <td width="0px" style="display: none;">' . $time . '</td> </tr>'; $fileJSArray .= "['" . $parsed_icon . "', '" . sanitize($entry) . "', '" . $parsed_size . "', '" . $parsed_time . "'],\n";
$opts['roots'][1] = array('driver' => 'LocalFileSystem', 'startPath' => SERVERPATH . '/' . THEMEFOLDER . '/' . $themeRequest, 'path' => SERVERPATH . '/' . THEMEFOLDER . '/' . $themeRequest, 'URL' => WEBPATH . '/' . THEMEFOLDER . '/' . $themeRequest, 'alias' => $themeAlias, 'mimeDetect' => 'internal', 'tmbPath' => '.tmb', 'utf8fix' => true, 'tmbCrop' => false, 'tmbBgColor' => 'transparent', 'accessControl' => 'access', 'acceptedName' => '/^[^\\.].*$/', 'attributes' => $attr = array(array('pattern' => '/.(' . implode('$|', $zplist) . '$)/', 'read' => true, 'write' => false, 'locked' => true), array('pattern' => '/.(' . implode('\\/|', $zplist) . '\\/)/', 'read' => true, 'write' => false, 'locked' => true))); } if ($rights & UPLOAD_RIGHTS) { $opts['roots'][2] = array('driver' => 'LocalFileSystem', 'startPath' => getAlbumFolder(SERVERPATH), 'path' => getAlbumFolder(SERVERPATH), 'URL' => getAlbumFolder(WEBPATH), 'alias' => sprintf(gettext('Albums folder (%s)'), basename(getAlbumFolder())), 'mimeDetect' => 'internal', 'tmbPath' => '.tmb', 'utf8fix' => true, 'tmbCrop' => false, 'tmbBgColor' => 'transparent', 'uploadAllow' => array('image'), 'acceptedName' => '/^[^\\.].*$/'); if ($rights & ADMIN_RIGHTS) { $opts['roots'][2]['accessControl'] = 'access'; } else { $opts['roots'][2]['accessControl'] = 'accessAlbums'; $_managed_folders = getManagedAlbumList(); $excluded_folders = $_zp_gallery->getAlbums(0); $excluded_folders = array_diff($excluded_folders, $_managed_folders); foreach ($excluded_folders as $key => $folder) { $excluded_folders[$key] = preg_quote($folder); } $maxupload = ini_get('upload_max_filesize'); $maxuploadint = parse_size($maxupload); $uploadlimit = zp_apply_filter('get_upload_limit', $maxuploadint); $all_actions = $_not_upload = $_not_edit = array(); foreach ($_managed_folders as $key => $folder) { $rightsalbum = newAlbum($folder); $modified_rights = $rightsalbum->subRights(); if ($uploadlimit <= 0) { $modified_rights = $modified_rights & ~MANAGED_OBJECT_RIGHTS_UPLOAD; } $_not_edit[$key] = $_not_upload[$key] = $folder = preg_quote($folder); switch ($modified_rights & (MANAGED_OBJECT_RIGHTS_UPLOAD | MANAGED_OBJECT_RIGHTS_EDIT)) { case MANAGED_OBJECT_RIGHTS_UPLOAD: // upload but not edit unset($_not_upload[$key]); break; case MANAGED_OBJECT_RIGHTS_EDIT:
<form action="api/upload_file" method="post" enctype="multipart/form-data" target="upload" id="upload-form"> <input type="hidden" name="max_file_size" value="<?php $upload_max_filesize = parse_size(ini_get('upload_max_filesize')); $post_max_size = parse_size(ini_get('post_max_size')); echo min($upload_max_filesize, $post_max_size); ?> "> <input type="file" name="file" id="attach_input" /> <iframe name="upload" class="hidden" border="0"></iframe> </form> <ul id="incoming_files"> <?php $dh = opendir(GRID_DIR . '/data/incoming'); while ($file = readdir($dh)) { if (substr($file, 0, 1) == '.') { continue; } $file = get_filename($file); echo "<li><a href=\"#\">{$file}</a></li>\n"; } ?> </ul>
$data = array(); } define('GALLERY_SESSION', @$data['album_session']); define('GALLERY_SECURITY', @$data['gallery_security']); unset($data); // insure a correct timezone if (function_exists('date_default_timezone_set')) { $level = error_reporting(0); $_zp_server_timezone = date_default_timezone_get(); date_default_timezone_set($_zp_server_timezone); @ini_set('date.timezone', $_zp_server_timezone); error_reporting($level); } // Set the memory limit higher just in case -- suppress errors if user doesn't have control. // 100663296 bytes = 96M if (ini_get('memory_limit') && parse_size(ini_get('memory_limit')) < 100663296) { @ini_set('memory_limit', '96M'); } // Set the internal encoding if (function_exists('mb_internal_encoding')) { @mb_internal_encoding(LOCAL_CHARSET); } // load graphics libraries in priority order // once a library has concented to load, all others will // abdicate. $_zp_graphics_optionhandlers = array(); $try = array('lib-GD.php', 'lib-NoGraphics.php'); if (getOption('use_imagick')) { array_unshift($try, 'lib-Imagick.php'); } while (!function_exists('zp_graphicsLibInfo')) {
/** * Fill image field with random images. * * @param Form $formObject * Form object. * @param string $field_name * Field name. * @param array $options * Options array. * * @return array * An array with 3 values: * (1) $success: Whether default values could be filled in the field. * (2) $values: Values that were filled for the field. * (3) $msg: Message in case there is an error. This will be empty if * $success is TRUE. */ public static function fillRandomValues(Form $formObject, $field_name, $options = array()) { $num = 1; $show_title = FALSE; $show_alt = FALSE; $scheme = 'public'; if (method_exists($formObject, 'getEntityObject')) { // This is an entity form. list($field, $instance, $num) = $formObject->getFieldDetails($field_name); $scheme = $field['settings']['uri_scheme']; $file_extensions = explode(' ', $instance['settings']['file_extensions']); $max_filesize = $instance['settings']['max_filesize']; $max_resolution = $instance['settings']['max_resolution']; $min_resolution = $instance['settings']['min_resolution']; $show_title = $instance['settings']['alt_field']; $show_alt = $instance['settings']['title_field']; } $min_width = ''; $max_width = ''; $min_height = ''; $max_height = ''; if (!empty($min_resolution)) { list($min_width, $min_height) = explode('x', $min_resolution); } if (!empty($max_resolution)) { list($max_width, $max_height) = explode('x', $max_resolution); } $files = file_scan_directory('tests/assets', '/.*\\.(' . implode('|', $file_extensions) . ')$/', array('recurse' => TRUE)); $valid_files = array(); foreach ($files as $uri => $file) { $image_info = image_get_info($uri); if (!empty($max_filesize) && $image_info['file_size'] > parse_size($max_filesize)) { continue; } if (!empty($min_width) && $image_info['width'] < $min_width) { continue; } if (!empty($max_width) && $image_info['width'] > $max_width) { continue; } if (!empty($min_height) && $image_info['height'] < $min_height) { continue; } if (!empty($max_height) && $image_info['height'] > $max_height) { continue; } $valid_files[$uri] = get_object_vars($file); } if (empty($valid_files)) { return new Response(FALSE, array(), "Appropriate image could not be found for {$field_name}."); } $files = array(); foreach (range(0, $num - 1) as $index) { $files[$index] = $valid_files[array_rand($valid_files)]; if ($show_title) { $files[$index]['title'] = Utils::getRandomText(20); } if ($show_alt) { $files[$index]['alt'] = Utils::getRandomText(20); } $files[$index]['scheme'] = $scheme; } $function = "fill" . Utils::makeTitleCase($field_name) . "Values"; return $formObject->{$function}($files); }
} } } $msg = Language::Get('main', 'successUploadSubmission', $langTemplate, array('exerciseName' => $exercise['name'])) . "<br>" . $errormsg; $notifications[] = MakeNotification('success', $msg); if ($isExpired) { $msg = Language::Get('main', 'successLateSubmission', $langTemplate, array('exerciseName' => $exercise['name'])); $notifications[] = MakeNotification('warning', $msg); } } else { $msg = Language::Get('main', 'errorUploadSubmissionSymbols', $langTemplate, array('status' => 412, 'exerciseName' => $exercise['name'])); $notifications[] = MakeNotification('error', $msg); } } else { if ($error === UPLOAD_ERR_INI_SIZE) { $msg = Language::Get('main', 'errorUploadSubmissionFileToLarge', $langTemplate, array('maxFileSize' => formatBytes(parse_size(ini_get('upload_max_filesize'))), 'status' => 412, 'exerciseName' => $exercise['name'])); $notifications[] = MakeNotification('error', $msg); } else { if ($error === UPLOAD_ERR_PARTIAL || $error === UPLOAD_ERR_NO_TMP_DIR || $error === UPLOAD_ERR_CANT_WRITE || $error === UPLOAD_ERR_EXTENSION) { $msg = Language::Get('main', 'errorUploadSubmission', $langTemplate, array('status' => 500, 'exerciseName' => $exercise['name'])); $notifications[] = MakeNotification('error', $msg); } } } } } } } // load user data from the database $URL = $getSiteURI . "/upload/user/{$uid}/course/{$cid}/exercisesheet/{$sid}"; $upload_data = http_get($URL, true);
/** * Function to return a string representing max import size by comparing values of upload_max_filesize, post_max_size * Uses parse_size helper function since the values in php.ini are strings like 64M and 128K * @return string */ function file_upload_max_size() { static $returnVal = false; // This function is adapted from Drupal and http://stackoverflow.com/questions/13076480/php-get-actual-maximum-upload-size if (false === $returnVal) { $post_max_size_str = ini_get('post_max_size'); $upload_max_filesize_str = ini_get('upload_max_filesize'); $post_max_size = parse_size($post_max_size_str); $upload_max_filesize = parse_size($upload_max_filesize_str); // If upload_max_size is less, then reduce. Except if upload_max_size is // zero, which indicates no limit. $returnVal = $post_max_size_str; if ($upload_max_filesize > 0 && $upload_max_filesize < $post_max_size) { $returnVal = $upload_max_filesize_str; } } return $returnVal; }
if (count($types) > 1) { printf(gettext('This web-based upload accepts the file formats: %s, and %s.'), $s1, $last); } else { printf(gettext('This web-based upload accepts the file formats: %s and %s.'), $s1, $last); } ?> </p> <p class="notebox"> <?php echo gettext('<strong>Note: </strong>'); if ($last == 'ZIP') { echo gettext('ZIP files must contain only Zenphoto supported <em>image</em> types.'); } $maxupload = ini_get('upload_max_filesize'); echo ' ' . sprintf(gettext("The maximum size for any one file is <strong>%sB</strong> which is set by your PHP configuration <code>upload_max_filesize</code>."), $maxupload); $maxupload = parse_size($maxupload); $uploadlimit = zp_apply_filter('get_upload_limit', $maxupload); $maxupload = min($maxupload, $uploadlimit); ?> <br /> <?php echo zp_apply_filter('get_upload_header_text', gettext('Don\'t forget, you can also use <acronym title="File Transfer Protocol">FTP</acronym> to upload folders of images into the albums directory!')); ?> </p> <?php if (isset($error) && $error) { ?> <div class="errorbox fade-message"> <h2><?php echo gettext("Something went wrong..."); ?>