_upload_file_limits
modules/upload/upload.module, строка 119
- Версии
- 6
_upload_file_limits($user)
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.
Параметры
$user
A Drupal user object.
Возвращаемое значение
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.
Код
<?php
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),
);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии