note 75799 deleted from features.file-upload by bjori
| From: | bjori@php.net | Date: | Sun, 17 Jun 2007 19:42:35 +0000 |
| Subject: | note 75799 deleted from features.file-upload by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127517@lists.php.net to get a copy of this message | ||
Note Submitter: info at jenom dot com
Reason: unreadable
----
For error-free file uploads:
============================
'post_max_size' - ; Maximum size of POST data that PHP will accept. See
'php.ini' normally in /etc
'upload_max_filesize' - ; Maximum allowed size for uploaded files. See
'php.ini' normally in /etc
'LimitRequestBody' - # Sets the file size limit for uploads via forms and such. See
'php.conf' normally in /etc/httpd/conf.d/
'LimitRequestBody' needs to be set in bytes, 'post_max_size' and
'upload_max_filesize' can be set in shorthand (ex. 10M)
Also, 'post_max_size' should to be set to a higher value than
'upload_max_filesize' since
post_max_size includes all the data being submitted by the form whereas upload_max_filesize
refers only to the size of the file being uploaded. So if there are additional fields in the
form being submitted (upload_max_filesize + data from other fields = post_max_size).
If upload_max_filesize = post_max_size you could get unexpected results, if there is other
data being sumitted.
'LimitRequestBody' corresponds with 'upload_max_filesize' those two values can
be the same.
In the actual html <form> block in your upload form you need to have:
'<input type="hidden" name="MAX_FILE_SIZE"
value="$max_filesize">' BEFORE
'<input type="file" name="upload_file_name"
size="50">'
To have the $max_file_size correspond to your php.ini and php.conf settings automatically,
use the function below
<?php
$max_filesize = parse_shorthand_size( ini_get('upload_max_filesize') );
function parse_shorthand_size( $sizein ) { //-> Parse shorthand size
values like 10K, 10M, 10G
$sizeout = 0;
$_arrsizes = array(
'k' => 10,
'm' => 20,
'g' => 30,
't' => 40,
'p' => 50,
'e' => 60,
'z' => 70,
'y' => 80,
);
if ( preg_match('/^([\d\.]+)([gmk])?$/i', $sizein, $n) ) { // If shorthand was used:
if ( isset($n['2']) ) { // $n[0] - original value, $n[1] - size (int), $n[2] -
units K, M, G
$unit_of_measure = strtolower($n['2']); // k - kilobytes, m - megabytes, g
- GIGABYTES ... y - Yotta (pronounced Yoda!!! O_O)
$sfactor = ( isset($_arrsizes[$unit_of_measure]) )
? $_arrsizes[$unit_of_measure]
: 0;
$sizeout = intval($n['1']) * ( pow(2, $sfactor) ); //-> PHP uses pow(
number $base, number $exp ) to calculate exponents
} else { //-> If shorthand was NOT used
$sizeout = ( isset($n['1']) )
? $n['1']
: 0;
}
}
return $sizeout;
} //-> end... function parse_shorthand_size( $sizein )
?>
I have learned a lot from all of you, time to give a little back. Keep up the great work.