本文整理匯總了PHP中jFile::getMimeTypeFromFilename方法的典型用法代碼示例。如果您正苦於以下問題:PHP jFile::getMimeTypeFromFilename方法的具體用法?PHP jFile::getMimeTypeFromFilename怎麽用?PHP jFile::getMimeTypeFromFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jFile
的用法示例。
在下文中一共展示了jFile::getMimeTypeFromFilename方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: check
function check()
{
if (isset($_FILES[$this->ref])) {
$this->fileInfo = $_FILES[$this->ref];
} else {
$this->fileInfo = array('name' => '', 'type' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE);
}
if ($this->fileInfo['error'] == UPLOAD_ERR_NO_FILE) {
if ($this->required) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
}
} else {
if ($this->fileInfo['error'] == UPLOAD_ERR_NO_TMP_DIR || $this->fileInfo['error'] == UPLOAD_ERR_CANT_WRITE) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_FILE_UPLOAD_ERROR;
}
if ($this->fileInfo['error'] == UPLOAD_ERR_INI_SIZE || $this->fileInfo['error'] == UPLOAD_ERR_FORM_SIZE || $this->maxsize && $this->fileInfo['size'] > $this->maxsize) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_SIZE;
}
if ($this->fileInfo['error'] == UPLOAD_ERR_PARTIAL || !is_uploaded_file($this->fileInfo['tmp_name'])) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID;
}
if (count($this->mimetype)) {
$this->fileInfo['type'] = jFile::getMimeType($this->fileInfo['tmp_name']);
if ($this->fileInfo['type'] == 'application/octet-stream') {
// let's try with the name
$this->fileInfo['type'] = jFile::getMimeTypeFromFilename($this->fileInfo['name']);
}
if (!in_array($this->fileInfo['type'], $this->mimetype)) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_TYPE;
}
}
}
return null;
}
示例2: getfile
public function getfile()
{
$module = $this->param('targetmodule');
if (!jApp::isModuleEnabled($module) || jApp::config()->modules[$module . '.access'] < 2) {
throw new jException('jelix~errors.module.untrusted', $module);
}
$rep = $this->getResponse('binary');
$rep->doDownload = false;
$dir = jApp::getModulePath($module) . 'www/';
$rep->fileName = realpath($dir . str_replace('..', '', $this->param('file')));
if (!is_file($rep->fileName)) {
$rep = $this->getResponse('html', true);
$rep->bodyTpl = 'jelix~404.html';
$rep->setHttpStatus('404', 'Not Found');
return $rep;
}
$rep->mimeType = jFile::getMimeTypeFromFilename($rep->fileName);
return $rep;
}