diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2011-04-17 12:03:23 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2011-04-17 12:03:23 +0200 |
commit | a14f8243e8b137fb57fa6071de7d1ebe7268866c (patch) | |
tree | bd107f63dfadcb246fdae407ff88371deb1d32b4 | |
parent | ab155de14fbc046d78b4eeaac0e8350c4b38dc98 (diff) | |
download | nextcloud-server-a14f8243e8b137fb57fa6071de7d1ebe7268866c.tar.gz nextcloud-server-a14f8243e8b137fb57fa6071de7d1ebe7268866c.zip |
get max upload file size for upload form from php settings
-rw-r--r-- | files/index.php | 1 | ||||
-rw-r--r-- | files/templates/index.php | 2 | ||||
-rw-r--r-- | lib/helper.php | 37 |
3 files changed, 39 insertions, 1 deletions
diff --git a/files/index.php b/files/index.php index 638f5d0c51e..e07e80aabb5 100644 --- a/files/index.php +++ b/files/index.php @@ -60,6 +60,7 @@ $tmpl = new OC_TEMPLATE( "files", "index", "user" ); $tmpl->assign( "files", $files ); $tmpl->assign( "breadcrumb", $breadcrumb ); $tmpl->assign( 'dir', $dir); +$tmpl->assign( 'uploadMaxFilesize', OC_HELPER::computerFileSize(ini_get('upload_max_filesize'))); $tmpl->printPage(); ?> diff --git a/files/templates/index.php b/files/templates/index.php index 49742a98136..40113c9fe0c 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -8,7 +8,7 @@ href="" title="" class="delete">Delete</a> <div id="file_upload_form"> <form action="ajax/upload.php" method="post" enctype="multipart/form-data" target="file_upload_target"><input -type="hidden" name="MAX_FILE_SIZE" value="2097152" id="max_upload"><input +type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_["uploadMaxFilesize"] ?>" id="max_upload"><input type="hidden" name="dir" value="<?php echo $_["dir"] ?>" id="dir"><input type="file" name="file" id="fileSelector"><input type="submit" id="file_upload_start" value="Upload" /><iframe id="file_upload_target" diff --git a/lib/helper.php b/lib/helper.php index 7c7fe2757e7..ff16d5894b8 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -119,6 +119,43 @@ class OC_HELPER { } /** + * @brief Make a computer file size + * @param $str file size in a fancy format + * @returns a file size in bytes + * + * Makes 2kB to 2048. + * + * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 + */ + public static function computerFileSize( $str ){ + $bytes = 0; + + $bytes_array = array( + 'B' => 1, + 'K' => 1024, + 'KB' => 1024, + 'MB' => 1024 * 1024, + 'M' => 1024 * 1024, + 'GB' => 1024 * 1024 * 1024, + 'G' => 1024 * 1024 * 1024, + 'TB' => 1024 * 1024 * 1024 * 1024, + 'T' => 1024 * 1024 * 1024 * 1024, + 'PB' => 1024 * 1024 * 1024 * 1024 * 1024, + 'P' => 1024 * 1024 * 1024 * 1024 * 1024, + ); + + $bytes = floatval($str); + + if (preg_match('#([KMGTP]?B?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { + $bytes *= $bytes_array[$matches[1]]; + } + + $bytes = intval(round($bytes, 2)); + + return $bytes; + } + + /** * @brief Recusive editing of file permissions * @param $path path to file or folder * @param $filemode unix style file permissions as integer |