本文整理汇总了PHP中file::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP file::getMimeType方法的具体用法?PHP file::getMimeType怎么用?PHP file::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file
的用法示例。
在下文中一共展示了file::getMimeType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkFile
public function checkFile($file, array $config)
{
if (!isset($config['params'])) {
return "Undefined MIME types.";
}
$type = file::getMimeType($file, isset($config['mime_magic']) ? $config['mime_magic'] : null);
$type = substr($type, 0, strrpos($type, ";"));
$mimes = $config['params'];
if (substr($mimes, 0, 1) == "!") {
$mimes = trim(substr($mimes, 1));
return in_array($type, explode(" ", $mimes)) ? "You can't upload such files." : true;
}
return !in_array($type, explode(" ", $mimes)) ? "You can't upload such files." : true;
}
示例2: file
/** Cache a file. The $type parameter might define the MIME type of the file
* or path to magic file to autodetect the MIME type. If you skip $type
* parameter the method will try with the default magic file. Autodetection
* of MIME type requires Fileinfo PHP extension used in file::getMimeType()
* @param string $file
* @param string $type
* @param integer $expire
* @param array $headers */
static function file($file, $type = null, $expire = null, array $headers = null)
{
$mtime = @filemtime($file);
if ($mtime !== false) {
self::checkMTime($mtime);
}
if ($type === null) {
$magic = substr($type, 0, 1) == "/" || preg_match('/^[a-z]\\:/i', $type) ? $type : null;
$type = file::getMimeType($file, $magic);
if (!$type) {
$type = null;
}
}
self::content(@file_get_contents($file), $mtime, $type, $expire, $headers, false);
}
示例3: checkUploadedFileMime
protected function checkUploadedFileMime($targetFile)
{
$targetFileResult = false;
if (!$targetFile || !file_exists($targetFile)) {
return false;
}
$targetFileResult = $targetFile;
if ($target_imagesize = @getimagesize($targetFile)) {
if (!function_exists('image_type_to_extension')) {
return false;
}
$renameResult = FALSE;
$targetFilePathInfo = pathinfo($targetFile);
// Get the EXPECTED EXTENSION from this MIME
$targetMimeInteger = $target_imagesize[2];
$expectedExtension = @image_type_to_extension($targetMimeInteger);
// get the existing MIME + MIME from the EXTENSION on this FILE ...
$targetMimeString = $target_imagesize['mime'];
$currentTargetMime = file::getMimeType($targetFile);
if ($expectedExtension && $currentTargetMime != $targetMimeString) {
// Ensure we use SHORTHAND JPG extensions ....
if ($expectedExtension == ".jpeg" && $this->shortHandJpgExtensions) {
$expectedExtension = ".jpg";
}
// Rename the extension from whatever it was previously to a new extension ...
$exptectedFileName = str_replace(".{$targetFilePathInfo['extension']}", $expectedExtension, $targetFile);
$expectedFileResult = array('target' => basename($targetFile), 'destination' => basename($exptectedFileName));
// Testing this code ...
// echo "<pre style='font-size:10px;'>";
// print_r($expectedFileResult);
// echo "</pre>";
// die();
$renameResult = @rename($targetFile, $exptectedFileName);
}
if ($renameResult) {
$targetFileResult = $exptectedFileName;
}
}
return $targetFile;
}