Siehe hierzu die umfangreichen Gedanken zum File-Upload.
Hm. Inzwischen zu groß (halbes Buch) geworden und unübersichtlich. Habe gerade am wiki-Eintrag herumgedoktort.
Die Berechnung der maximalen Upload-Größe scheint nicht ganz trivial. Wie würdet Ihr das machen?
<?php
class ini_max_filesize {
public $max_filesize = 0;
public $upload_max_filesize = 0;
public $post_max_size = 0;
public $symbols = 'KMGTPEZ';
public $arSymbols = false;
function __construct () {
$this-> arSymbols = array_merge( [''], str_split( $this-> symbols ) );
$this -> upload_max_filesize = $this -> extval2integer( ini_get('upload_max_filesize') );
$this -> post_max_size = $this -> extval2integer( ini_get('post_max_size') );
if ( $this -> upload_max_filesize < $this -> post_max_size ) {
$this -> max_filesize = $this -> upload_max_filesize;
} else {
$this -> max_filesize = $this -> post_max_size;
}
}
function extval2integer ( $val ) {
if ( 0 == (int)$val ) {
return PHP_INT_MAX;
} else {
$symbol = strtoupper( preg_replace( '/[^' . $this -> symbols . ']/', '', $val ));
return 1024 ** array_search( $symbol, $this -> arSymbols ) * (int)$val ;
}
}
}
?>
<input type="hidden" name="MAX_FILE_SIZE" value="<?= ( new ini_max_filesize() ) -> max_filesize; ?>">
Resultat mit
upload_max_filesize = 2M
post_max_size = 8M
in der php.ini:
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">