当前位置: 首页>>代码示例>>PHP>>正文


PHP CFileHelper::getMimeType方法代码示例

本文整理汇总了PHP中CFileHelper::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP CFileHelper::getMimeType方法的具体用法?PHP CFileHelper::getMimeType怎么用?PHP CFileHelper::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFileHelper的用法示例。


在下文中一共展示了CFileHelper::getMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run($class_name)
 {
     $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
     $class_name = ucfirst($class_name);
     if ($path && is_dir($path) && is_writable($path)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $pk = pathinfo($filename, PATHINFO_FILENAME);
         $image = Images::model()->findByPk($pk);
         if ($image != null) {
             $image->resize($dir);
         }
     } elseif (class_exists($class_name)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $size = explode('x', $dir);
         $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
         if (YII_DEBUG && !file_exists($path . DIRECTORY_SEPARATOR . $dir)) {
             mkdir($path . DIRECTORY_SEPARATOR . $dir, 0777);
         }
         if ($path !== FALSE && file_exists($path . DIRECTORY_SEPARATOR . $dir) && is_file($path . DIRECTORY_SEPARATOR . $filename) && $size[0] > 0 && $size[1] > 0) {
             Yii::import('ext.iwi.Iwi');
             $image = new Iwi($path . DIRECTORY_SEPARATOR . $filename);
             $image->adaptive($size[0], $size[1]);
             $image->save($path . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $filename, 0644, TRUE);
             $mime = CFileHelper::getMimeType($path . DIRECTORY_SEPARATOR . $filename);
             header('Content-Type: ' . $mime);
             $image->render();
             exit;
         }
     }
     return parent::run($class_name);
 }
开发者ID:BGCX067,项目名称:facecom-svn-to-git,代码行数:33,代码来源:UploadController.php

示例2: run

 public function run($thumb)
 {
     $key = key($_GET);
     if (NULL == ($file = Files::model()->findByPk($key))) {
         throw new CException('Page not found', 404);
     }
     $path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'photos';
     $src_file = $file->id . '.' . $file->extension;
     $in_file = $path . DIRECTORY_SEPARATOR . $src_file;
     $out_file = $path . DIRECTORY_SEPARATOR . $thumb . DIRECTORY_SEPARATOR . $src_file;
     if (is_file($out_file)) {
         $mime = CFileHelper::getMimeType($out_file);
         header('Content-Type: ' . $mime);
         readfile($out_file);
         exit;
     }
     if (is_file($in_file)) {
         $dir = $path . DIRECTORY_SEPARATOR . $thumb;
         if (YII_DEBUG && !file_exists($dir)) {
             mkdir($dir, 0777);
         }
         if (file_exists($dir)) {
             if (($out_file = $file->resize($thumb)) == 0) {
                 throw new CException('Page not found', 404);
             }
             $mime = CFileHelper::getMimeType($in_file);
             header('Content-Type: ' . $mime);
             readfile($out_file);
             exit;
         }
     }
     return parent::run($thumb);
 }
开发者ID:BGCX067,项目名称:facecom-svn-to-git,代码行数:33,代码来源:ImagesController.php

示例3: create

 /**
  * @static
  * @param $fullPath
  * @return bool|CsvImage
  */
 public static function create($fullPath)
 {
     if (!file_exists($fullPath)) {
         return false;
     }
     $name = explode(DS, $fullPath);
     return new C1ProductImage(end($name), $fullPath, CFileHelper::getMimeType($fullPath), filesize($fullPath), false);
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:13,代码来源:C1ProductImage.php

示例4: isAllowedType

 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     return in_array($type, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'));
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:12,代码来源:ShopUploadedImage.php

示例5: isAllowedType

 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     return in_array($type, EventsImagesConfig::get('types'));
 }
开发者ID:bahdall,项目名称:karbella_event,代码行数:12,代码来源:EventsUploadedImage.php

示例6: isAllowedType

 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     //return in_array($type, Yii::app()->params['storeImages']['types']);
     return in_array($type, StoreImagesConfig::get('types'));
 }
开发者ID:Aplay,项目名称:myhistorypark_site,代码行数:13,代码来源:FileImageValidator.php

示例7: getExtensionByMimeType

 /**
  * @param string $fileName
  * @return string
  */
 public static function getExtensionByMimeType($fileName)
 {
     $mimeTypes = (require Yii::getPathOfAlias('system.utils.mimeTypes') . '.php');
     $unsetArray = array('jpe', 'jpeg');
     foreach ($unsetArray as $key) {
         unset($mimeTypes[$key]);
     }
     $mimeType = CFileHelper::getMimeType($fileName);
     return (string) array_search($mimeType, $mimeTypes);
 }
开发者ID:DarkAiR,项目名称:test,代码行数:14,代码来源:EFileHelper.php

示例8: actionGenerate

 /**
  * Generates a thumbnail for the specified image path and size, then serves 
  * it to the browser. The next time the same thumbnail is rendered its URL 
  * will point to the generated image instead of this action.
  * @see Thumbnail
  * @param string $path the thumbnail path
  * @param int $size the thumbnail size
  * @throws PageNotFoundException if the image could not be generated
  */
 public function actionGenerate($path, $size)
 {
     $thumbnail = new Thumbnail($path, $size);
     $thumbnail->generate();
     $path = $thumbnail->getPath();
     if ($path === false) {
         throw new PageNotFoundException();
     }
     header('Content-Type: ' . CFileHelper::getMimeType($path));
     readfile($path);
     exit;
 }
开发者ID:Tebro,项目名称:xbmc-video-server,代码行数:21,代码来源:ThumbnailController.php

示例9: run

 /**
  * Runs the action.
  */
 public function run()
 {
     foreach (Yii::app()->log->routes as $route) {
         if ($route instanceof CWebLogRoute || $route instanceof CFileLogRoute || $route instanceof YiiDebugToolbarRoute) {
             $route->enabled = false;
         }
     }
     $asset = $_GET['path'];
     #修改为action读取文件资料
     $SAECommon = new SAECommon();
     $path = $SAECommon->saedisk_decrypt($asset);
     if (!file_exists($path)) {
         throw new CHttpException(404, Yii::t('yii', 'The asset "{asset}" to be published does not exist.', array('{asset}' => $asset)));
     }
     // 浏览器根据etag来缓存,增加 date('H') 则为一小时更新
     $etag = md5($path + date('d'));
     header("ETag: {$etag}");
     $offset = 60 * 60 * 24;
     //css文件的距离现在的过期时间,这里设置为一天
     $expire = "expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
     header($expire);
     $type = CFileHelper::getMimeType($path);
     header("content-type: {$type}; charset: UTF-8");
     //注意修改到你的编码
     #header ("cache-control: max-age=$offset,must-revalidate");
     header("cache-control: max-age={$offset}");
     #header ("Pragma:");
     #print_r($_SERVER['HTTP_IF_NONE_MATCH']);die;
     if (isset($_SERVER['HTTP_IF_NONE_MATCH']) and $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
         #header('HTTP/1.1 304 Not Modified');
         header('Etag:' . $etag, true, 304);
     } else {
         if (extension_loaded('zlib')) {
             //检查服务器是否开启了zlib拓展
             ob_start('ob_gzhandler');
         }
         //加载文件
         //include($path);
         echo file_get_contents($path);
         if (extension_loaded('zlib')) {
             ob_end_flush();
             //输出buffer中的内容,即压缩后的css文件
         }
     }
     exit;
 }
开发者ID:daysun1987,项目名称:daydaynews,代码行数:49,代码来源:SAEAssetsAction.php

示例10: actionUpload

 /**
  * 上传课时视频
  * Enter description here ...
  */
 public function actionUpload($lessonId)
 {
     $model = $this->loadModel($lessonId);
     if (isset($_FILES['file']['name'])) {
         $fileTypes = array('mp4', 'flv');
         // File extensions
         $fileParts = pathinfo($_FILES['file']['name']);
         if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
             $tempFile = $_FILES['file']['tmp_name'];
             //向uploadfile表中插入记录
             $uploadFile = new UploadFile();
             $uploadFile->userId = Yii::app()->user->id;
             $uploadFile->addTime = time();
             $uploadFile->mime = CFileHelper::getMimeType($tempFile) ? CFileHelper::getMimeType($tempFile) : "video/mp4";
             $uploadFile->name = $_FILES['file']['name'];
             $uploadFile->size = $_FILES['file']['size'];
             $uploadFile->storage = 'local';
             $uploadFile->save();
             //得到id,并以此为文件名保存视频文件
             $id = $uploadFile->id;
             $path = 'uploads/uploadFile/Lesson/mediaId';
             if (!is_dir($path)) {
                 mkdir($path, 0777, true);
             }
             $path .= '/' . $id . "." . $fileParts['extension'];
             move_uploaded_file($tempFile, $path);
             $uploadFile->path = $path;
             $uploadFile->save();
             //清除旧数据
             $model->deleteMedia();
             $model->mediaType = "video";
             $model->mediaId = $uploadFile->getPrimaryKey();
             $model->save();
             //返回mediaId
             //	echo json_encode(array('id'=>$id,'status'=>'success'));
             //echo json_encode($uploadFile->name);
             echo true;
         } else {
             //echo json_encode(array('status'=>'fail'));
             //	echo json_encode(null);
             echo false;
         }
     }
     $this->layout = "/layouts/nonav_column1";
     $this->render('upload_fancy', array('model' => $model));
 }
开发者ID:stan5621,项目名称:eduwind,代码行数:50,代码来源:LessonController.php

示例11: actionFile

public function actionFile($id){

        $id   = (int)$id;
        $model = City::model()->findByPk($id); 
        if(!$model)
            throw new CHttpException(404, Yii::t('site','Page not found'));

       // if(Yii::app()->user->isGuest && $model->issue->is_public !== true)
       //     Yii::app()->user->loginRequired();

        $available_mime = Yii::app()->params['mime_fileview'];

        $filename = $model->filename;
        $realname = $model->realname;

        $uploadPath = $model->getFileFolder();    

        if(file_exists($uploadPath.$filename )) {

            $type = CFileHelper::getMimeType($uploadPath.$filename); // get yii framework mime
            
            if(in_array($type, $available_mime)){

                //.. get the content of the requested file 
                $content=file_get_contents($uploadPath.$filename);
                //.. send appropriate headers
                header('Content-Type:' . $type);
                header("Content-Length: ". filesize($uploadPath.$filename));

                header('Content-Disposition: inline; filename="' . $realname . '"');
                header('Content-Transfer-Encoding: binary');
                header('Accept-Ranges: bytes');

                echo $content;
                exit; 
                
            } else {
                throw new CHttpException(404, Yii::t('site','Page not found'));
            }
        }
        else{
            throw new CHttpException(404, Yii::t('site','Page not found'));
        }   

    }
开发者ID:Aplay,项目名称:Fastreview_site,代码行数:45,代码来源:CityController.php

示例12: actionGet

 public function actionGet()
 {
     $key = Yii::app()->request->getParam('key', null);
     if ($key != null) {
         $key = base64_decode($key);
         $key = str_replace('/', '', $key);
         $user_id = isset(Yii::app()->user->id) ? Yii::app()->user->id : 0;
         $dir = dirname(__FILE__) . '/../../shared/' . $user_id . '/';
         if (is_dir($dir)) {
             if (file_exists($dir . '/' . $key)) {
                 header("Pragma: public");
                 header("Expires: 0");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Cache-Control: private", false);
                 header("Content-Disposition: attachment; filename=\"" . $key . "\";");
                 header('Content-type: ' . CFileHelper::getMimeType($dir . '/' . $key));
                 header("Content-Transfer-Encoding: binary");
                 readfile($dir . '/' . $key);
                 die;
             }
         }
         // list mentor directories
         $mentors = SchoolMentor::model()->findAll('user_id=:user_id', array(':user_id' => $user_id));
         $key = mb_substr($key, 1, mb_strlen($key, 'UTF-8') - 1, 'UTF-8');
         foreach ($mentors as $mentor) {
             $dir = dirname(__FILE__) . '/../../shared/M' . $mentor->id . '/';
             if (is_dir($dir)) {
                 if (file_exists($dir . '/' . $key)) {
                     header("Pragma: public");
                     header("Expires: 0");
                     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                     header("Cache-Control: private", false);
                     header("Content-Disposition: attachment; filename=\"" . $key . "\";");
                     header('Content-type: ' . CFileHelper::getMimeType($dir . '/' . $key));
                     header("Content-Transfer-Encoding: binary");
                     readfile($dir . '/' . $key);
                     die;
                 }
             }
         }
     }
 }
开发者ID:lidijakralj,项目名称:bober,代码行数:42,代码来源:SharedController.php

示例13: create

 /**
  * @param string $image name in ./uploads/importImages/ e.g. somename.jpg
  * @return CsvImage
  */
 public static function create($image)
 {
     $isDownloaded = substr($image, 0, 5) === 'http:';
     if ($isDownloaded) {
         $tmpName = Yii::getPathOfAlias('application.runtime') . DIRECTORY_SEPARATOR . sha1(pathinfo($image, PATHINFO_FILENAME)) . '.' . pathinfo($image, PATHINFO_EXTENSION);
         if ((bool) parse_url($image) && !file_exists($tmpName)) {
             $fileHeader = get_headers($image, 1);
             if ((int) substr($fileHeader[0], 9, 3) === 200) {
                 file_put_contents($tmpName, file_get_contents($image));
             }
         }
     } else {
         $tmpName = Yii::getPathOfAlias('webroot.uploads.importImages') . DIRECTORY_SEPARATOR . $image;
     }
     if (!file_exists($tmpName)) {
         return false;
     }
     $result = new CsvImage($image, $tmpName, CFileHelper::getMimeType($tmpName), filesize($tmpName), false);
     $result->isDownloaded = $isDownloaded;
     return $result;
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:25,代码来源:CsvImage.php

示例14: run

 /**
  * Runs the action.
  */
 public function run()
 {
     if (!Yii::app()->getRequest()->getIsPostRequest()) {
         throw new CHttpException(400, Yii::t('app', 'Invalid request. Please do not repeat this request again.'));
     }
     $folder = Yii::app()->params['uploadTargetPath'];
     $model = new $this->modelClass();
     $fk = $this->foreignKey;
     if (isset($_REQUEST[$fk]) && ($id = (int) $_REQUEST[$fk]) > 0) {
         $model->{$fk} = $id;
     }
     $result = $this->saveFile($folder);
     if (!isset($result['success'])) {
         throw new CHttpException(400, Yii::t('app', 'Error saving uploaded file.'));
     }
     $filePath = $folder . DIRECTORY_SEPARATOR . $result['filename'];
     $size = getimagesize($filePath);
     if (isset($_REQUEST['qqfile'])) {
         $model->filename = $_REQUEST['qqfile'];
     } elseif (isset($_FILES['qqfile']['name'])) {
         $model->filename = $_FILES['qqfile']['name'];
     }
     $model->content = file_get_contents($filePath);
     $model->size = filesize($filePath);
     $model->mimetype = CFileHelper::getMimeType($filePath);
     if ($size !== false) {
         list($width, $height, $type, $attr) = $size;
         $model->width = $width;
         $model->height = $height;
     }
     if ($model->save(false)) {
         echo json_encode(array_merge($result, array('id' => $model->primaryKey)));
     } else {
         echo json_encode(array('errors' => $model->getErrors()));
     }
     Yii::app()->end();
 }
开发者ID:nineinchnick,项目名称:eajaxupload,代码行数:40,代码来源:UploadSaveAction.php

示例15: actionAnyFile

 public function actionAnyFile($id, $model = 'Partner', $filename = 'image', $realname = false)
 {
     $id = (int) $id;
     $model = $model::model()->findByPk($id);
     if (!$model) {
         throw new CHttpException(404, Yii::t('site', 'Page not found'));
     }
     $available_mime = Yii::app()->params['mime_fileview'];
     $filename = $model->{$filename};
     $uploadPath = $model->getFileFolder();
     if (file_exists($uploadPath . $filename)) {
         $type = CFileHelper::getMimeType($uploadPath . $filename);
         // get yii framework mime
         if (in_array($type, $available_mime)) {
             //.. get the content of the requested file
             $content = file_get_contents($uploadPath . $filename);
             //.. send appropriate headers
             header('Content-Type:' . $type);
             header("Content-Length: " . filesize($uploadPath . $filename));
             if ($realname) {
                 $realname = $model->{$realname};
                 header('Content-Disposition: inline; filename="' . $realname . '"');
             } else {
                 header('Content-Disposition: inline; filename="' . $filename . '"');
             }
             header('Content-Transfer-Encoding: binary');
             header('Accept-Ranges: bytes');
             echo $content;
             exit;
         } else {
             throw new CHttpException(404, Yii::t('site', 'Page not found'));
         }
     } else {
         throw new CHttpException(404, Yii::t('site', 'Page not found'));
     }
 }
开发者ID:Aplay,项目名称:myhistorypark_site,代码行数:36,代码来源:FileController.php


注:本文中的CFileHelper::getMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。