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


PHP FileHelper類代碼示例

本文整理匯總了PHP中FileHelper的典型用法代碼示例。如果您正苦於以下問題:PHP FileHelper類的具體用法?PHP FileHelper怎麽用?PHP FileHelper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: handleFileUpload

 /**
  * Override parent
  */
 function handleFileUpload($fileParameters, $id)
 {
     $filename = NULL;
     if (array_key_exists($this->parameterFile, $_FILES) and array_key_exists('name', $_FILES[$this->parameterFile]) and $_FILES[$this->parameterFile]['name'] != '') {
         $fileHelper = new FileHelper();
         $filename = $fileHelper->upload($this->fileBasename, $id, $_FILES[$this->parameterFile]);
     }
     return $filename;
 }
開發者ID:replicair,項目名稱:Replicair-website,代碼行數:12,代碼來源:PressReviewController.php

示例2: updateTagRelationCache

 public static function updateTagRelationCache($manualLock = false)
 {
     if (!$manualLock) {
         self::checkTagRelationCache('lock');
     }
     try {
         $tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php";
         $c = new Criteria();
         $allTags = TagPeer::doSelect($c);
         $content = "<?php \n";
         foreach ($allTags as $singleTag) {
             $c = new Criteria();
             $c->add(TagrelationPeer::TAG_ID, $singleTag->getId());
             $tagRelations = TagrelationPeer::doSelect($c);
             if ($tagRelations) {
                 $elementsArr = "array(";
                 foreach ($tagRelations as $tagRelation) {
                     $elementsArr .= $tagRelation->getId() . ",";
                 }
                 $content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n";
             }
         }
         $content .= "\n?>";
         if (FileHelper::writeFile($tagRelationsFile, $content)) {
             BackendService::loadTagsRelations();
         } else {
             echo FileHelper::Log("Unable to write tag cache in: " . $tagRelationsFile, UtilsHelper::MSG_ERROR);
         }
     } catch (Exception $e) {
         echo FileHelper::Log("Unable to refresh tag cache: " . $e->getMessage(), UtilsHelper::MSG_ERROR);
     }
     if (!$manualLock) {
         self::checkTagRelationCache('unlock');
     }
 }
開發者ID:kotow,項目名稱:work,代碼行數:35,代碼來源:Tagrelation.php

示例3: writeFile

 public static function writeFile($file)
 {
     $supported_image = array('gif', 'jpg', 'jpeg', 'png');
     // get the file extension
     $extension = $file->getClientOriginalExtension();
     // make it lowercase
     $extension = strtolower($extension);
     // check if it is valid
     if (!in_array($extension, $supported_image)) {
         // if is not valid, return an error
         $obj = new stdClass();
         $obj->success = false;
         $obj->error = $extension . " is not an valid image type!";
         return $obj;
     }
     // add extension to name
     $name = FileHelper::generateRandomString(10);
     $name = $name . '.' . $extension;
     // create the file
     $file->move(__DIR__ . '/images', $name);
     // return an success message
     $obj = new stdClass();
     $obj->success = true;
     $obj->message = "Image successfully uploaded!";
     $obj->imagePath = $name;
     return $obj;
 }
開發者ID:BoldijarPaul,項目名稱:upload-image-backend,代碼行數:27,代碼來源:FileHelper.php

示例4: applyTo

 public function applyTo($path)
 {
     return parent::applyTo($path);
     $pathMap = $this->pathMap;
     if (empty($pathMap)) {
         if (($basePath = $this->getBasePath()) === null) {
             throw new InvalidConfigException('The "basePath" property must be set.');
         }
         $pathMap = [Yii::$app->getBasePath() => [$basePath]];
     }
     $path = FileHelper::normalizePath($path);
     foreach ($pathMap as $from => $tos) {
         $from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
         if (strpos($path, $from) === 0) {
             $n = strlen($from);
             foreach ((array) $tos as $to) {
                 $to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
                 $file = $to . substr($path, $n);
                 if (is_file($file)) {
                     return $file;
                 }
             }
         }
     }
     return $path;
 }
開發者ID:martin20140408,項目名稱:lulucms2,代碼行數:26,代碼來源:Theme.php

示例5: build

 public function build($runData)
 {
     // get current backups
     $site = $runData->getTemp("site");
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $sb = DB_SiteBackupPeer::instance()->selectOne($c);
     if ($sb) {
         if ($sb->getStatus() == "completed") {
             // get backup file size
             $path = WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName() . '/backup/' . $sb->getRand() . '/backup.zip';
             // check if file exists
             if (!file_exists($path)) {
                 // in case something failed
                 DB_SiteBackupPeer::instance()->delete($c);
                 $sb = null;
             } else {
                 $size = filesize($path);
                 $sizeFormatted = FileHelper::formatSize($size);
                 $runData->contextAdd('size', $sizeFormatted);
             }
         }
     }
     $runData->contextAdd("site", $site);
     $runData->contextAdd("backup", $sb);
 }
開發者ID:jbzdak,項目名稱:wikidot,代碼行數:26,代碼來源:ManageSiteBackupModule.php

示例6: actionDownload_client

 public function actionDownload_client()
 {
     $afterDownload = false;
     if (isset($_POST['download'])) {
         $currentUser = Yii::app()->db->createCommand("SELECT * FROM external_users_usr WHERE id_usr=" . Yii::app()->user->userId)->queryRow();
         if ($currentUser['password_usr'] == ExternalUser::model()->passwordHash($_POST['password'])) {
             $afterDownload = true;
             $_SESSION['password'] = $_POST['password'];
         } else {
             Yii::app()->user->setFlash('_error', 'Wrong password!');
         }
     }
     if (isset($_GET['download'])) {
         $currentUser = Yii::app()->db->createCommand("SELECT * FROM external_users_usr WHERE id_usr=" . Yii::app()->user->userId)->queryRow();
         if ($currentUser['password_usr'] == ExternalUser::model()->passwordHash($_SESSION['password'])) {
             $password = $_SESSION['password'];
             $afterDownload = true;
             $tmpPath = VIREX_TEMP_PATH;
             $variables = array('START_DATE' => date('Y-m-d', strtotime('- 7 day')), 'END_DATE' => date('Y-m-d'), 'USERNAME' => $currentUser['name_usr'], 'PASSWORD' => $password, 'BASE_URL' => VIREX_URL);
             // step 1. Create username dir
             if (file_exists($tmpPath . '/' . $currentUser['name_usr'])) {
                 if (file_exists($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.inc')) {
                     unlink($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.inc');
                 }
                 if (file_exists($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.php')) {
                     unlink($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.php');
                 }
             } else {
                 mkdir($tmpPath . '/' . $currentUser['name_usr']);
             }
             $tmpPath = $tmpPath . '/' . $currentUser['name_usr'] . '/';
             // step 2. copy originaly files
             copy(VIREX_APP_PATH . '/protected/sampleshareclient/sampleshare.inc', $tmpPath . 'sampleshare.inc');
             copy(VIREX_APP_PATH . '/protected/sampleshareclient/sampleshare.php', $tmpPath . 'sampleshare.php');
             // step 3. replace variables
             $original = file_get_contents($tmpPath . 'sampleshare.php');
             foreach ($variables as $k => $v) {
                 $original = str_replace('<!--' . $k . '--!>', $v, $original);
             }
             file_put_contents($tmpPath . 'sampleshare.php', $original);
             // step 4. create zip archive
             $files = array($tmpPath . 'sampleshare.inc', $tmpPath . 'sampleshare.php');
             FileHelper::packFiles($files, $tmpPath, 'zip.zip');
             // step 5. download contents
             header('Content-Type: application/octet-stream');
             header('Content-Disposition: attachment; filename="norman-sampleshare-client-example.zip"');
             header('Content-Transfer-Encoding: binary');
             readfile($tmpPath . 'zip.zip');
             // step 6. clean folder
             unlink($tmpPath . 'sampleshare.inc');
             unlink($tmpPath . 'sampleshare.php');
             unlink($tmpPath . 'zip.zip');
             rmdir($tmpPath);
             unset($_SESSION['password']);
         } else {
             Yii::app()->user->setFlash('_error', 'Wrong password!');
         }
     }
     $this->render('download_client', array('afterDownload' => $afterDownload));
 }
開發者ID:vman747,項目名稱:virex,代碼行數:60,代碼來源:SiteController.php

示例7: actionIndex

 /**
  * 管理員上傳
  */
 function actionIndex()
 {
     $name = $_REQUEST['field'];
     if (!$name) {
         exit;
     }
     $file = new FileHelper();
     $file->uid = Yii::app()->user->id;
     $file->admin = 1;
     $rt = $file->upload();
     if (!$rt) {
         return;
     }
     $new[] = $rt;
     $out = FileHelper::input($new, $name);
     echo $out;
     exit;
 }
開發者ID:hiproz,項目名稱:mincms,代碼行數:21,代碼來源:PluploadController.php

示例8: Build

 /**
  * Populates Source View Model
  * @return Source_Vm
  */
 public function Build()
 {
     $fname = FileHelper::getFilename();
     $data = FileHelper::getFile(Config::$SongDirectory . $fname);
     $viewModel = new Source_Vm();
     $viewModel->PageTitle = 'Song Source for &quot;' . $fname . '&quot; ChordPro (CPM)/UkeGeeks File Format';
     $viewModel->Body = htmlspecialchars($data);
     return $viewModel;
 }
開發者ID:hikusukih,項目名稱:UkeGeeks,代碼行數:13,代碼來源:Source_Vmb.php

示例9: actionPost

 public function actionPost()
 {
     $model = new PostResumeForm(Yii::app()->user->id);
     //check max job post
     if ($model->getCountUserJobs() < Yii::app()->params['maxResumeJobTitles']) {
         if (isset($_POST['PostResumeForm'])) {
             $model->attributes = $_POST['PostResumeForm'];
             $model->resumeFile = CUploadedFile::getInstance($model, 'resumeFile');
             $model->portfolioFile = CUploadedFile::getInstance($model, 'portfolioFile');
             if ($model->validate()) {
                 //checks the number of job titles submitted are within the limit boundry
                 if (count($model->jobTitles) + $model->getCountUserJobs() > Yii::app()->params['maxResumeJobTitles']) {
                     Yii::app()->user->setFlash('warning', sprintf(Yii::t('app', 'msg.warning.max_job_titles_exceed'), Yii::app()->params['maxResumeJobTitles']));
                     $this->redirect(Yii::app()->createAbsoluteUrl($this->getModule()->returnUrl));
                     Yii::app()->end();
                     return;
                 }
                 $extension = FileHelper::getExtension($model->resumeFile->name);
                 if (!empty($model->portfolioFile->name)) {
                     $extension_PortFolio = FileHelper::getExtension($model->portfolioFile->name);
                 } else {
                     $extension_PortFolio = "";
                 }
                 //saved file name in the following pattern
                 // {user_id}cv{time_stamp_string}.{extension}
                 $fileName = Yii::app()->user->id . 'cv' . Yii::app()->dateFormatter->format('yyyy-MM-dd_H-mm-ss', time()) . '.' . $extension;
                 if (!empty($extension_PortFolio)) {
                     $fileName_PortFolio = Yii::app()->user->id . 'pf' . Yii::app()->dateFormatter->format('yyyy-MM-dd_H-mm-ss', time()) . '.' . $extension_PortFolio;
                 } else {
                     $fileName_PortFolio = "";
                 }
                 if ($model->save(Yii::app()->user->id, $fileName, $fileName_PortFolio)) {
                     //if(!empty($fileName_PortFolio))
                     //{
                     $userFilePath = FileHelper::getFilePath(Yii::getPathOfAlias('site.files') . '/resumes/' . Yii::app()->user->id . '/');
                     $model->resumeFile->saveAs($userFilePath . $fileName);
                     if (!empty($fileName_PortFolio)) {
                         $model->portfolioFile->saveAs($userFilePath . $fileName_PortFolio);
                     }
                     Yii::app()->user->setFlash('success', Yii::t('app', 'msg.success.post_resume'));
                     //}
                 }
                 //checks the number of job titles submitted are within the limit boundry
                 if (count($model->jobTitles) + $model->getCountUserJobs() > Yii::app()->params['maxResumeJobTitles']) {
                     $this->refresh(true);
                 } else {
                     $this->redirect($this->createAbsoluteUrl('index'));
                 }
             }
         }
         $this->render('post', array('model' => $model));
     } else {
         Yii::app()->user->setFlash('warning', sprintf(Yii::t('app', 'msg.warning.max_job_titles_exceed'), Yii::app()->params['maxResumeJobTitles']));
         $this->redirect(Yii::app()->createAbsoluteUrl($this->getModule()->returnUrl));
     }
 }
開發者ID:aakbar24,項目名稱:CollegeCorner_Ver_2.0,代碼行數:56,代碼來源:ResumePostController.php

示例10: actionDownload

 public function actionDownload($name, $id)
 {
     if ($name !== null) {
         $userFilePath = Yii::getPathOfAlias('site.files') . '/workshops/' . $id;
         $userFilePath .= "/" . $name;
         if (!FileHelper::outputFile($name, $userFilePath)) {
             throw new CHttpException(404, 'File not found');
         }
     }
 }
開發者ID:aakbar24,項目名稱:CollegeCorner_Ver_2.0,代碼行數:10,代碼來源:FileController.php

示例11: fetchDataBasicAuthenticationTmpFile

 /**
  * Fetches (with curl) a binary or normal file (via http or https) from a remote site as string using HTTPBasicAuth.
  * EXAMPLE: FileHelper::fetchDataBasicAuthentication('http://localhost/bli/bla/blum.xml','username','password');
  * @param string $url of the data to fetch
  * @param string $usr optional username (do not use HTTPBasicAuth if $usr==NULL); default: NULL
  * @param string $pass optional password; default: ''
  * @return string $filename OR FALSE if HTTP_RESPONSE >= 400. If larger than the PHP memory limit the request should crash - this is actually a security feature?
  * @static
  */
 function fetchDataBasicAuthenticationTmpFile($url, $postData = null, $usr = NULL, $pass = '')
 {
     $fn = tempnam("/tmp", "tmpFH");
     $data = FileHelper::fetchDataBasicAuthentication($url, $postData, $usr, $pass);
     if ($data == FALSE) {
         return FALSE;
     }
     file_put_contents($fn, $data);
     return $fn;
 }
開發者ID:netiul,項目名稱:cgkutrechtwest-gadgets,代碼行數:19,代碼來源:FileHelper.class.php

示例12: _getRealFilePath

 /**
  * Generate the actual filesystem path for a filekey
  */
 protected function _getRealFilePath($filekey, $createDir = true)
 {
     $filekey = substr(sha1($filekey), 0, 32);
     $path = sprintf('%s/%s/', rtrim($this->_filepath, '/'), substr($filekey, 0, self::STUB_KEY_LENGTH));
     // ensure directory path exists
     if ($createDir && !is_dir($path)) {
         FileHelper::createDirectory($path);
     }
     return $path . $filekey;
 }
開發者ID:99designs,項目名稱:cabinet,代碼行數:13,代碼來源:FilesystemFileStore.php

示例13: getFile

 public static function getFile($fileName, $fileType = 'csv')
 {
     //make sure the file name is unqiue
     $fileName = Yii::$app->getRuntimePath() . '/temp/' . $fileName . '.' . strtolower($fileType);
     $filePath = dirname($fileName);
     if (!is_dir($filePath)) {
         FileHelper::createDirectory($filePath, 0777, true);
     }
     return $fileName;
 }
開發者ID:timelessmemory,項目名稱:uhkklp,代碼行數:10,代碼來源:ExportSampleRecord.php

示例14: mapRowToObject

 /**
  * Map a database row result to object
  * 
  * @param array $row
  * @return PressReview
  */
 function mapRowToObject($row)
 {
     $pressReview = new PressReview();
     $pressReview->id = $row['id'];
     $pressReview->source = stripslashes($row['sourceInfo']);
     $pressReview->author = stripslashes($row['author']);
     $pressReview->label = stripslashes($row['label']);
     $pressReview->url = stripslashes($row['url']);
     $pressReview->file = $row['filename'];
     $pressReview->date = $row['dateEvent'];
     $pressReview->state = $row['state'];
     //echo "label : ".$row['label'];
     //echo "label : ".stripslashes($row['label']);
     //echo "label : ".$pressReview->label;
     if ($pressReview->file != NULL) {
         $fileHelper = new FileHelper();
         $pressReview->fileType = $fileHelper->getFileType($pressReview->file);
     }
     return $pressReview;
 }
開發者ID:replicair,項目名稱:Replicair-website,代碼行數:26,代碼來源:PressReviewService.php

示例15: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->uploadRootPath) {
         throw new InvalidConfigException('The "savePath" attribute must be set.');
     } else {
         $this->uploadRootPath = rtrim(Yii::getAlias($this->uploadRootPath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         if (!file_exists($this->uploadRootPath) && !FileHelper::createDirectory($this->uploadRootPath)) {
             throw new InvalidCallException('Directory specified in "savePath" attribute doesn\'t exist or cannot be created.');
         }
     }
 }
開發者ID:EugeneJk,項目名稱:yii2-custom-fields,代碼行數:15,代碼來源:ImageCropAction.php


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