本文整理汇总了PHP中file_storage::mimetype方法的典型用法代码示例。如果您正苦于以下问题:PHP file_storage::mimetype方法的具体用法?PHP file_storage::mimetype怎么用?PHP file_storage::mimetype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file_storage
的用法示例。
在下文中一共展示了file_storage::mimetype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_upload
/**
* Do the actual processing of the uploaded file
* @param string $saveas_filename name to give to the file
* @param int $maxbytes maximum file size
* @param mixed $types optional array of file extensions that are allowed or '*' for all
* @param string $savepath optional path to save the file to
* @param int $itemid optional the ID for this item within the file area
* @param string $license optional the license to use for this file
* @param string $author optional the name of the author of this file
* @param bool $overwriteexisting optional user has asked to overwrite the existing file
* @param int $areamaxbytes maximum size of the file area.
* @return object containing details of the file uploaded
*/
public function process_upload($saveas_filename, $maxbytes, $types = '*', $savepath = '/', $itemid = 0, $license = null, $author = '', $overwriteexisting = false, $areamaxbytes = FILE_AREA_MAX_BYTES_UNLIMITED)
{
global $USER, $CFG;
if (is_array($types) and in_array('*', $types) or $types == '*') {
$this->mimetypes = '*';
} else {
foreach ($types as $type) {
$this->mimetypes[] = mimeinfo('type', $type);
}
}
if ($license == null) {
$license = $CFG->sitedefaultlicense;
}
$record = new stdClass();
$record->filearea = 'draft';
$record->component = 'user';
$record->filepath = $savepath;
$record->itemid = $itemid;
$record->license = $license;
$record->author = $author;
$context = context_user::instance($USER->id);
$elname = 'repo_upload_file';
$fs = get_file_storage();
$sm = get_string_manager();
if ($record->filepath !== '/') {
$record->filepath = file_correct_filepath($record->filepath);
}
if (!isset($_FILES[$elname])) {
throw new moodle_exception('nofile');
}
if (!empty($_FILES[$elname]['error'])) {
switch ($_FILES[$elname]['error']) {
case UPLOAD_ERR_INI_SIZE:
throw new moodle_exception('upload_error_ini_size', 'repository_upload');
break;
case UPLOAD_ERR_FORM_SIZE:
throw new moodle_exception('upload_error_form_size', 'repository_upload');
break;
case UPLOAD_ERR_PARTIAL:
throw new moodle_exception('upload_error_partial', 'repository_upload');
break;
case UPLOAD_ERR_NO_FILE:
throw new moodle_exception('upload_error_no_file', 'repository_upload');
break;
case UPLOAD_ERR_NO_TMP_DIR:
throw new moodle_exception('upload_error_no_tmp_dir', 'repository_upload');
break;
case UPLOAD_ERR_CANT_WRITE:
throw new moodle_exception('upload_error_cant_write', 'repository_upload');
break;
case UPLOAD_ERR_EXTENSION:
throw new moodle_exception('upload_error_extension', 'repository_upload');
break;
default:
throw new moodle_exception('nofile');
}
}
\core\antivirus\manager::scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true);
// {@link repository::build_source_field()}
$sourcefield = $this->get_file_source_info($_FILES[$elname]['name']);
$record->source = self::build_source_field($sourcefield);
if (empty($saveas_filename)) {
$record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
} else {
$ext = '';
$match = array();
$filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
if (strpos($filename, '.') === false) {
// File has no extension at all - do not add a dot.
$record->filename = $saveas_filename;
} else {
if (preg_match('/\\.([a-z0-9]+)$/i', $filename, $match)) {
if (isset($match[1])) {
$ext = $match[1];
}
}
$ext = !empty($ext) ? $ext : '';
if (preg_match('#\\.(' . $ext . ')$#i', $saveas_filename)) {
// saveas filename contains file extension already
$record->filename = $saveas_filename;
} else {
$record->filename = $saveas_filename . '.' . $ext;
}
}
}
// Check the file has some non-null contents - usually an indication that a user has
// tried to upload a folder by mistake
//.........这里部分代码省略.........
示例2: process_upload
/**
* Do the actual processing of the uploaded file
* @param string $saveas_filename name to give to the file
* @param int $maxbytes maximum file size
* @param mixed $types optional array of file extensions that are allowed or '*' for all
* @param string $savepath optional path to save the file to
* @param int $itemid optional the ID for this item within the file area
* @param string $license optional the license to use for this file
* @param string $author optional the name of the author of this file
* @return object containing details of the file uploaded
*/
public function process_upload($saveas_filename, $maxbytes, $types = '*', $savepath = '/', $itemid = 0, $license = null, $author = '') {
global $USER, $CFG;
if ((is_array($types) and in_array('*', $types)) or $types == '*') {
$this->mimetypes = '*';
} else {
foreach ($types as $type) {
$this->mimetypes[] = mimeinfo('type', $type);
}
}
if ($license == null) {
$license = $CFG->sitedefaultlicense;
}
$record = new stdClass();
$record->filearea = 'draft';
$record->component = 'user';
$record->filepath = $savepath;
$record->itemid = $itemid;
$record->license = $license;
$record->author = $author;
$context = get_context_instance(CONTEXT_USER, $USER->id);
$elname = 'repo_upload_file';
$fs = get_file_storage();
$sm = get_string_manager();
if ($record->filepath !== '/') {
$record->filepath = file_correct_filepath($record->filepath);
}
if (!isset($_FILES[$elname])) {
throw new moodle_exception('nofile');
}
if (!empty($_FILES[$elname]['error'])) {
switch ($_FILES[$elname]['error']) {
case UPLOAD_ERR_INI_SIZE:
throw new moodle_exception('upload_error_ini_size', 'repository_upload');
break;
case UPLOAD_ERR_FORM_SIZE:
throw new moodle_exception('upload_error_form_size', 'repository_upload');
break;
case UPLOAD_ERR_PARTIAL:
throw new moodle_exception('upload_error_partial', 'repository_upload');
break;
case UPLOAD_ERR_NO_FILE:
throw new moodle_exception('upload_error_no_file', 'repository_upload');
break;
case UPLOAD_ERR_NO_TMP_DIR:
throw new moodle_exception('upload_error_no_tmp_dir', 'repository_upload');
break;
case UPLOAD_ERR_CANT_WRITE:
throw new moodle_exception('upload_error_cant_write', 'repository_upload');
break;
case UPLOAD_ERR_EXTENSION:
throw new moodle_exception('upload_error_extension', 'repository_upload');
break;
default:
throw new moodle_exception('nofile');
}
}
// scan the files, throws exception and deletes if virus found
// this is tricky because clamdscan daemon might not be able to access the files
$permissions = fileperms($_FILES[$elname]['tmp_name']);
@chmod($_FILES[$elname]['tmp_name'], $CFG->filepermissions);
self::antivir_scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true);
@chmod($_FILES[$elname]['tmp_name'], $permissions);
if (empty($saveas_filename)) {
$record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
} else {
$ext = '';
$match = array();
$filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
if (preg_match('/\.([a-z0-9]+)$/i', $filename, $match)) {
if (isset($match[1])) {
$ext = $match[1];
}
}
$ext = !empty($ext) ? $ext : '';
if (preg_match('#\.(' . $ext . ')$#i', $saveas_filename)) {
// saveas filename contains file extension already
$record->filename = $saveas_filename;
} else {
$record->filename = $saveas_filename . '.' . $ext;
}
//.........这里部分代码省略.........