Пример #1
0
 }
 if ($upload_destination_file != '') {
     //Check if file conforms to desired max size and width
     $image_size = '';
     $width = 0;
     $heigh = 0;
     $image_size = getimagesize($upload_destination_file);
     if ($image_size) {
         $width = $image_size[0];
         $height = $image_size[1];
         //Get allowable height and width
         if ($max_attachment_height == 0 || $max_attachment_width == 0) {
             require_once 'subclasses/system_settings.php';
             $obj_settings = new system_settings();
             if ($max_attachment_height == 0) {
                 $max_attachment_height = $obj_settings->get('Max Attachment Height', FALSE)->dump['value'];
             }
             if ($max_attachment_width == 0) {
                 $max_attachment_width = $obj_settings->get('Max Attachment Width', FALSE)->dump['value'];
             }
         }
         //Check if uploaded image conforms to limits, if there are any
         if ($max_attachment_height > 0 || $max_attachment_width > 0) {
             //If one dimension is 0 (or less; just to handle negative cases c/o incorrect config by admin), treat it as "no limit".
             if ($max_attachment_height <= 0) {
                 if ($width > $max_attachment_width) {
                     ${$file_upload_control_name} = '';
                     $message .= "File (" . $orig_filename . ") was not uploaded; image is too wide. Max width should only be {$max_attachment_width} px<br>";
                 }
             } elseif ($max_attachment_width <= 0) {
                 if ($height > $max_attachment_height) {
Пример #2
0
<?php

require_once 'subclasses/system_settings.php';
$obj_settings = new system_settings();
$max_attachment_size_MB = $obj_settings->get('Max Attachment Size (MB)', FALSE)->dump['value'];
if ($max_attachment_size_MB < 1) {
    //This means the setting is set to auto-detect ini values, misconfigured, or has been removed.
    //Whatever the case, get sensible max size by getting post_max_size and upload_max_filesize, and using the lower value
    if (!function_exists('return_bytes')) {
        function return_bytes($val)
        {
            //This is taken from phpmanual, as their recommended way of querying for memory size values
            $val = trim($val);
            $last = strtoupper($val[strlen($val) - 1]);
            switch ($last) {
                case 'G':
                    $val *= 1024;
                case 'M':
                    $val *= 1024;
                case 'K':
                    $val *= 1024;
            }
            return $val;
        }
    }
    $ini_post_max_size = return_bytes(ini_get('post_max_size'));
    $ini_upload_max_filesize = return_bytes(ini_get('upload_max_filesize'));
    if ($ini_post_max_size < $ini_upload_max_filesize) {
        $max_attachment_size = $ini_post_max_size;
    } else {
        $max_attachment_size = $ini_upload_max_filesize;