當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FileToolkit::validateFileExtension方法代碼示例

本文整理匯總了PHP中Topxia\Common\FileToolkit::validateFileExtension方法的典型用法代碼示例。如果您正苦於以下問題:PHP FileToolkit::validateFileExtension方法的具體用法?PHP FileToolkit::validateFileExtension怎麽用?PHP FileToolkit::validateFileExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Topxia\Common\FileToolkit的用法示例。


在下文中一共展示了FileToolkit::validateFileExtension方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: uploadFile

 public function uploadFile($group, File $file, $target = null)
 {
     $errors = FileToolkit::validateFileExtension($file);
     if ($errors) {
         @unlink($file->getRealPath());
         throw $this->createServiceException("該文件格式,不允許上傳。");
     }
     $group = $this->getGroupDao()->findGroupByCode($group);
     $user = $this->getCurrentUser();
     if (!$user->isLogin()) {
         throw $this->createServiceException("用戶尚未登錄。");
     }
     $record = array();
     $record['userId'] = $user['id'];
     $record['groupId'] = $group['id'];
     // @todo fix it.
     $record['mime'] = '';
     // $record['mime'] = $file->getMimeType();
     $record['size'] = $file->getSize();
     $record['uri'] = $this->generateUri($group, $file);
     $record['createdTime'] = time();
     $record = $this->getFileDao()->addFile($record);
     $record['file'] = $this->saveFile($file, $record['uri']);
     return $record;
 }
開發者ID:robert-li-2015,項目名稱:EduSoho,代碼行數:25,代碼來源:FileServiceImpl.php

示例2: addFile

 public function addFile(array $fileInfo = array(), UploadedFile $originalFile = null)
 {
     $errors = FileToolkit::validateFileExtension($originalFile);
     if ($errors) {
         @unlink($originalFile->getRealPath());
         throw $this->createServiceException("該文件格式,不允許上傳。");
     }
     $uploadFile = array();
     $uploadFile['storage'] = 'local';
     $uploadFile['filename'] = $originalFile->getClientOriginalName();
     $uploadFile['ext'] = FileToolkit::getFileExtension($originalFile);
     $uploadFile['size'] = $originalFile->getSize();
     $filename = FileToolkit::generateFilename($uploadFile['ext']);
     $uploadFile['hashId'] = "course/{$filename}";
     $uploadFile['convertHash'] = "ch-{$uploadFile['hashId']}";
     $uploadFile['convertStatus'] = 'none';
     $uploadFile['type'] = FileToolkit::getFileTypeByExtension($uploadFile['ext']);
     $uploadFile['isPublic'] = empty($fileInfo['isPublic']) ? 0 : 1;
     $uploadFile['canDownload'] = empty($uploadFile['canDownload']) ? 0 : 1;
     $uploadFile['updatedUserId'] = $uploadFile['createdUserId'] = $this->getCurrentUser()->id;
     $uploadFile['updatedTime'] = $uploadFile['createdTime'] = time();
     $targetPath = $this->getFilePath('course', $uploadFile['isPublic']);
     $originalFile->move($targetPath, $filename);
     return $uploadFile;
 }
開發者ID:liugang19890719,項目名稱:www.zesow.com,代碼行數:25,代碼來源:LocalFileImplementorImpl.php

示例3: validateExcelFile

 public function validateExcelFile($file)
 {
     $errorMessage = '';
     if (!is_object($file)) {
         $errorMessage = '請選擇上傳的文件';
         return $errorMessage;
     }
     if (FileToolkit::validateFileExtension($file, 'xls xlsx')) {
         $errorMessage = 'Excel格式不正確!';
         return $errorMessage;
     }
     $this->excelAnalyse($file);
     if ($this->rowTotal > 1000) {
         $message = 'Excel超過1000行數據!';
         return $errorMessage;
     }
     if (!$this->checkNecessaryFields($this->excelFields)) {
         $message = '缺少必要的字段';
         return $errorMessage;
     }
     return $errorMessage;
 }
開發者ID:ccq18,項目名稱:EduSoho,代碼行數:22,代碼來源:ClassroomUserImporterProcessor.php

示例4: uploadAction

 public function uploadAction(Request $request)
 {
     try {
         $token = $request->query->get('token');
         $maker = new UploadToken();
         $token = $maker->parse($token);
         if (empty($token)) {
             throw new \RuntimeException("上傳授權碼已過期,請刷新頁麵後重試!");
         }
         $file = $request->files->get('upload');
         if ($token['type'] == 'image') {
             if (!FileToolkit::isImageFile($file)) {
                 throw new \RuntimeException("您上傳的不是圖片文件,請重新上傳。");
             }
         } elseif ($token['type'] == 'flash') {
             $errors = FileToolkit::validateFileExtension($file, 'swf');
             if (!empty($errors)) {
                 throw new \RuntimeException("您上傳的不是Flash文件,請重新上傳。");
             }
         } else {
             throw new \RuntimeException("上傳類型不正確!");
         }
         $record = $this->getFileService()->uploadFile($token['group'], $file);
         $funcNum = $request->query->get('CKEditorFuncNum');
         $url = $this->get('topxia.twig.web_extension')->getFilePath($record['uri']);
         if ($token['type'] == 'image') {
             $response = "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', function(){ this._.dialog.getParentEditor().insertHtml('<img src=\"{$url}\">'); this._.dialog.hide(); return false; });</script>";
         } else {
             $response = "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}');</script>";
         }
         return new Response($response);
     } catch (\Exception $e) {
         $message = $e->getMessage();
         $funcNum = $request->query->get('CKEditorFuncNum');
         $response = "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '', '{$message}');</script>";
         return new Response($response);
     }
 }
開發者ID:liugang19890719,項目名稱:www.zesow.com,代碼行數:38,代碼來源:EditorController.php

示例5: addFile

 public function addFile($targetType, $targetId, array $fileInfo = array(), UploadedFile $originalFile = null)
 {
     $errors = FileToolkit::validateFileExtension($originalFile);
     if ($errors) {
         @unlink($originalFile->getRealPath());
         throw $this->createServiceException("該文件格式,不允許上傳。");
     }
     $uploadFile = array();
     $time = time();
     $uploadFile['storage'] = 'local';
     $uploadFile['targetId'] = $targetId;
     $uploadFile['targetType'] = $targetType;
     $uploadFile['filename'] = $originalFile->getClientOriginalName();
     //$uploadFile['filename'] = $time.$uploadFile['filename'];
     $uploadFile['ext'] = FileToolkit::getFileExtension($originalFile);
     $uploadFile['size'] = $originalFile->getSize();
     $filename = FileToolkit::generateFilename($uploadFile['ext']);
     $uploadFile['hashId'] = "{$uploadFile['targetType']}/{$uploadFile['targetId']}/{$filename}";
     $uploadFile['convertHash'] = "ch-{$uploadFile['hashId']}";
     $uploadFile['convertStatus'] = 'none';
     $uploadFile['type'] = FileToolkit::getFileTypeByExtension($uploadFile['ext']);
     $uploadFile['isPublic'] = empty($fileInfo['isPublic']) ? 0 : 1;
     $uploadFile['canDownload'] = empty($uploadFile['canDownload']) ? 0 : 1;
     $uploadFile['updatedUserId'] = $uploadFile['createdUserId'] = $this->getCurrentUser()->id;
     $uploadFile['updatedTime'] = $uploadFile['createdTime'] = time();
     //$uploadFile['filePath'] = $this->getFilePath();
     //throw new \RuntimeException(print_r('ssd'));
     //throw $this->createServiceException(print_r('ssd'));
     //$key = $uploadFile['filename'];
     //qiniu();
     //轉存上傳臨時文件到資源文件夾(由於業務服務器硬盤較小,故不作備份,直接上傳到七牛雲。如需開啟則刪除下麵注釋符) 以下代碼未包含刪備份
     $targetPath = $this->getFilePath($targetType, $targetId, $uploadFile['isPublic']);
     $originalFile->move($targetPath, $filename);
     //todo 上傳到七牛處理代碼(存儲、轉碼、拚接、水印)20151224
     //$config = $this->getQiniuService()->initQiniu($targetPath,$filename);
     return $uploadFile;
 }
開發者ID:Loyalsoldier,項目名稱:8000wei-v3,代碼行數:37,代碼來源:LocalFileImplementorImpl.php

示例6: uploadAction

 public function uploadAction(Request $request)
 {
     $group = $request->query->get('group');
     $file = $this->get('request')->files->get('file');
     if (!is_object($file)) {
         throw $this->createNotFoundException('上傳文件不能為空!');
     }
     if (filesize($file) > 1024 * 1024 * 2) {
         throw $this->createNotFoundException('上傳文件大小不能超過2MB!');
     }
     if (FileToolkit::validateFileExtension($file, 'png jpg gif doc xls txt rar zip')) {
         throw $this->createNotFoundException('文件類型不正確!');
     }
     $record = $this->getFileService()->uploadFile($group, $file);
     //$record['url'] = $this->get('topxia.twig.web_extension')->getFilePath($record['uri']);
     unset($record['uri']);
     $record['name'] = $file->getClientOriginalName();
     return new Response(json_encode($record));
 }
開發者ID:Loyalsoldier,項目名稱:8000wei-v2,代碼行數:19,代碼來源:GroupThreadController.php


注:本文中的Topxia\Common\FileToolkit::validateFileExtension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。