shoprex-icon-big

Shoprex

Developer site for the Wordpress Plugin Shoprex

Show maximum file size for upload in PHP


‘post_max_size’ and ‘upload_max_filesize’ specify in php.ini how large a file for upload can be.

In the example, the lowest value is calculated and displayed in Megabytes:

 function return_size($val) 
{ 
   $val = trim($val); // Remove Spaces 
   $last = strtolower($val[strlen($val)-1]); // 
   Type switch($last) // Type 
   { 
      case 'g': // Gigabyte 
         $val /= 1024; 
         break; 
      case 'm': // Megabyte 
         $val *= 1; // convert to number 
         break; 
      case 'k': // Kilobyte 
         $val *= 1024; 
         break; 
      } 
   return $val; 
} 

function return_max_upload() 
{ 
   $val1 = ini_get('post_max_size'); 
   $val2 = ini_get('upload_max_filesize'); 
   $val1 = return_size($val1); 
   $val2 = return_size($val2); 
   if($val1 <= $val2) // Determine the lowest value 
   { return $val1; } 
   else 
   { return $val2; } 
} 


Back

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
*