function _upload_file_limits in Drupal 6
Determine the limitations on files that a given user may upload. The user may be in multiple roles so we select the most permissive limitations from all of their roles.
Parameters
$user: A Drupal user object.
Return value
An associative array with the following keys: 'extensions' A white space separated string containing all the file extensions this user may upload. 'file_size' The maximum size of a file upload in bytes. 'user_size' The total number of bytes for all for a user's files. 'resolution' A string specifying the maximum resolution of images.
2 calls to _upload_file_limits()
- upload_node_form_submit in modules/
upload/ upload.module - Save new uploads and store them in the session to be associated to the node on upload_save.
- _upload_form in modules/
upload/ upload.module
File
- modules/
upload/ upload.module, line 119 - File-handling and attaching files to nodes.
Code
function _upload_file_limits($user) {
$file_limit = variable_get('upload_uploadsize_default', 1);
$user_limit = variable_get('upload_usersize_default', 1);
$all_extensions = explode(' ', variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'));
foreach ($user->roles as $rid => $name) {
$extensions = variable_get("upload_extensions_{$rid}", variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'));
$all_extensions = array_merge($all_extensions, explode(' ', $extensions));
// A zero value indicates no limit, take the least restrictive limit.
$file_size = variable_get("upload_uploadsize_{$rid}", variable_get('upload_uploadsize_default', 1)) * 1024 * 1024;
$file_limit = $file_limit && $file_size ? max($file_limit, $file_size) : 0;
$user_size = variable_get("upload_usersize_{$rid}", variable_get('upload_usersize_default', 1)) * 1024 * 1024;
$user_limit = $user_limit && $user_size ? max($user_limit, $user_size) : 0;
}
$all_extensions = implode(' ', array_unique($all_extensions));
return array(
'extensions' => $all_extensions,
'file_size' => $file_limit,
'user_size' => $user_limit,
'resolution' => variable_get('upload_max_resolution', 0),
);
}