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


PHP FileHelper::createDirectory方法代码示例

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


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

示例1: actionUpload

 /**
  * @return string
  */
 public function actionUpload()
 {
     /* @var Cloud*/
     $cloud = Cloud::getInst();
     $path = $cloud->storage->getPath();
     $uploader = new UploadHandler();
     FileHelper::createDirectory($path);
     // Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
     $uploader->allowedExtensions = [];
     // all files types allowed by default
     // Specify max file size in bytes.
     $uploader->sizeLimit = 20 * 1024 * 1024;
     // default is 10 MiB
     $method = Yii::$app->request->getMethod();
     if ($method == "POST") {
         // Assumes you have a chunking.success.endpoint set to point here with a query parameter of "done".
         // For example: /myserver/handlers/endpoint.php?done
         if (isset($_GET["done"])) {
             $result = $uploader->combineChunks($path);
         } else {
             // Call handleUpload() with the name of the folder, relative to PHP's getcwd()
             $result = $uploader->handleUpload($path, uniqid());
             // To return a name used for uploaded file you can use the following line.
             $result["uploadName"] = $uploader->getUploadName();
         }
         return Json::encode($result);
     } else {
         if ($method == "DELETE") {
             $result = $uploader->handleDelete($path);
             return Json::encode($result);
         }
     }
 }
开发者ID:pavlinter,项目名称:yii2-app-core,代码行数:36,代码来源:FineUploaderController.php

示例2: clusterization

 protected function clusterization()
 {
     $flattenTransitionMatrix = $this->matrix->flatten(Matrix::FLATTEN_MATRIX_BY_INDEX);
     $path = \Yii::getAlias('@runtime/transition_cluster');
     FileHelper::createDirectory($path);
     /** @var string $filename Temp file */
     $filename = tempnam($path, 'tmp');
     // Write strings to file
     $f = fopen($filename, 'w');
     foreach ($flattenTransitionMatrix as $key => $value) {
         fwrite($f, $value['source'] . "\t" . $value['target'] . "\t" . $value['value'] . PHP_EOL);
     }
     // matrix diagonal cells for consistent output
     foreach ($this->matrix->getWindowIds() as $key => $winId) {
         fwrite($f, $key . "\t" . $key . "\t" . '0' . PHP_EOL);
     }
     fclose($f);
     chmod($filename, 0666);
     // make clusters
     $cmdPath = \Yii::getAlias('@app/scikit/transition-cluster.py');
     $cmd = "python {$cmdPath} {$filename}";
     $clusterRaw = [];
     $exitCode = 0;
     $result = exec($cmd, $clusterRaw, $exitCode);
     if ($exitCode != 0) {
         return [];
         //            throw new Exception('Can\'t run cluster command. ' . $result);
     }
     unlink($filename);
     $winIdCluster = [];
     foreach ($this->matrix->getWindowIds() as $key => $winId) {
         $winIdCluster[$winId] = $clusterRaw[$key];
     }
     return $winIdCluster;
 }
开发者ID:alxkolm,项目名称:php-selftop,代码行数:35,代码来源:AffinityClusterization.php

示例3: prepareDestinationFileName

 /**
  * Prepares raw destination file name for the file copy/move operation:
  * resolves path alias and creates missing directories.
  * @param string $destinationFileName destination file name
  * @return string real destination file name
  */
 protected function prepareDestinationFileName($destinationFileName)
 {
     $destinationFileName = Yii::getAlias($destinationFileName);
     $destinationPath = dirname($destinationFileName);
     FileHelper::createDirectory($destinationPath);
     return $destinationFileName;
 }
开发者ID:yii2tech,项目名称:html2pdf,代码行数:13,代码来源:TempFile.php

示例4: upload

 public function upload($file = 'file', $rules = array(), $type = NULL)
 {
     $this->file = UploadedFile::getInstance($this, $file);
     if (!empty($rules)) {
         //createValidator
     }
     if ($this->validate()) {
         $this->realname = $this->file->getBaseName();
         $this->alt = $this->realname;
         $this->ext = $this->file->getExtension();
         $this->type = $type ? $type : '';
         do {
             $this->path = static::random('hexdec', 3) . '/' . static::random('hexdec', 3);
         } while (file_exists($this->_server_path('original')));
         $this->alt = urldecode($_FILES['image']['name']);
         $this->timestamp = time();
         FileHelper::createDirectory($this->_server_path(), 0775, TRUE);
         if (!file_exists($this->_server_path())) {
             exit;
         }
         $this->save();
         $this->file->saveAs($this->_server_path('original'));
         return $this->resize($this->type);
     } else {
         return $model->errors;
     }
 }
开发者ID:Kulkow,项目名称:mainsite,代码行数:27,代码来源:Image.php

示例5: clusterizeStrings

 public static function clusterizeStrings(array $windows)
 {
     $path = \Yii::getAlias('@runtime/string_cluster');
     FileHelper::createDirectory($path);
     /** @var string $filename Temp file */
     $filename = tempnam($path, 'tmp');
     // Write strings to file
     $f = fopen($filename, 'w');
     foreach ($windows as $win) {
         fwrite($f, $win['title'] . PHP_EOL);
     }
     fclose($f);
     chmod($filename, 0666);
     // make clusters
     $cmdPath = \Yii::getAlias('@app/scikit/string-cluster.py');
     $cmd = "python {$cmdPath} < {$filename}";
     $clusterRaw = [];
     $exitCode = 0;
     $result = exec($cmd, $clusterRaw, $exitCode);
     if ($exitCode != 0) {
         return [];
         //            throw new Exception('Can\'t run cluster command. ' . $result);
     }
     unlink($filename);
     // Transform results
     $winIdCluster = [];
     foreach ($windows as $key => $window) {
         $winIdCluster[$window['id']] = $clusterRaw[$key];
     }
     return [$clusterRaw, $winIdCluster];
 }
开发者ID:alxkolm,项目名称:php-selftop,代码行数:31,代码来源:ClusterHelper.php

示例6: actionIndex

 public function actionIndex($name, $type)
 {
     $dir = Yii::getAlias("@webroot/{$this->dir}/_{$type}/");
     if (file_exists($dir . $name)) {
         $this->printFile($dir . $name);
     }
     FileHelper::createDirectory($dir);
     $crop = 1;
     if (strpos($type, 'x') !== false) {
         list($width, $height) = explode('x', trim($type, '!^'));
         if (!$width || !$height || strpos($type, '^')) {
             $crop = 0;
         } elseif (strpos($type, '!')) {
             $crop = 2;
         }
     } else {
         $width = $height = $type;
         $crop = 0;
     }
     $fromDir = Yii::getAlias("@webroot/{$this->dir}/tmp/");
     $from = $fromDir . $name;
     if (!file_exists($from)) {
         $name = 'default.jpg';
         $fromDir = Yii::getAlias("@runtime/");
         file_put_contents($fromDir . $name, base64_decode($this->default));
     }
     $thumb = Image::thumbnail(Yii::getAlias($fromDir . $name), $width, $height, $crop);
     $thumb->save($dir . $name, ['quality' => $this->quality, 'png_compression_level' => 9]);
     $this->printFile($dir . $name);
 }
开发者ID:RAPanel,项目名称:yii2-image,代码行数:30,代码来源:ImageController.php

示例7: actionUpload

 /**
  * Закачивает файл `$_FILES['file']`
  *
  * @return string JSON Response
  *                [[
  *                    $tempUploadedFileName,
  *                    $fileName
  *                ]]
  */
 public function actionUpload()
 {
     $this->actionUpload_clearTempFolder();
     $output_dir = FileUploadMany::$uploadDirectory;
     $info = parse_url($_SERVER['HTTP_REFERER']);
     if ($info['host'] != $_SERVER['SERVER_NAME']) {
         return self::jsonError('Не тот сайт');
     }
     if (isset($_FILES['file'])) {
         $file = $_FILES['file'];
         $ret = [];
         $error = $file['error'];
         //You need to handle  both cases
         //If Any browser does not support serializing of multiple files using FormData()
         if (!is_array($file['name'])) {
             $fileName = \cs\services\UploadFolderDispatcher::generateFileName($file['name']);
             $destPathFull = Yii::getAlias($output_dir);
             FileHelper::createDirectory($destPathFull);
             $destPathFull = $destPathFull . '/' . $fileName;
             move_uploaded_file($file['tmp_name'], $destPathFull);
             $ret[] = [$fileName, $file['name']];
         } else {
             $fileCount = count($file['name']);
             $dir = Yii::getAlias($output_dir);
             for ($i = 0; $i < $fileCount; $i++) {
                 $fileName = $file['name'][$i];
                 move_uploaded_file($file['tmp_name'][$i], $dir . '/' . $fileName);
                 $ret[] = [$fileName, $file['name'][$i]];
             }
         }
         return self::jsonSuccess($ret);
     }
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:42,代码来源:UploadController.php

示例8: init

 /**
  * @throws \rmrevin\yii\minify\Exception
  */
 public function init()
 {
     parent::init();
     if (php_sapi_name() !== 'cli') {
         $urlDetails = \Yii::$app->urlManager->parseRequest(\Yii::$app->request);
         if (in_array($urlDetails[0], $this->exclude_routes)) {
             $this->enableMinify = false;
         }
     }
     $minify_path = $this->minify_path = (string) \Yii::getAlias($this->minify_path);
     if (!file_exists($minify_path)) {
         helpers\FileHelper::createDirectory($minify_path);
     }
     if (!is_readable($minify_path)) {
         throw new Exception('Directory for compressed assets is not readable.');
     }
     if (!is_writable($minify_path)) {
         throw new Exception('Directory for compressed assets is not writable.');
     }
     if (true === $this->compress_output) {
         \Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function (\yii\base\Event $Event) {
             /** @var \yii\web\Response $Response */
             $Response = $Event->sender;
             if ($Response->format === \yii\web\Response::FORMAT_HTML) {
                 if (!empty($Response->data)) {
                     $Response->data = HtmlCompressor::compress($Response->data, ['extra' => true]);
                 }
                 if (!empty($Response->content)) {
                     $Response->content = HtmlCompressor::compress($Response->content, ['extra' => true]);
                 }
             }
         });
     }
 }
开发者ID:synackSA,项目名称:yii2-minify-view,代码行数:37,代码来源:View.php

示例9: upload

 /**
  * @return \app\modules\document\models\Attachment|bool
  * @throws \yii\base\Exception
  */
 public function upload()
 {
     if ($this->validate()) {
         $root = \Yii::getAlias('@webroot');
         $path = '/uploads/' . date('Y-m-d');
         $uploadPath = $root . $path;
         $file = $this->file;
         //check for the existence of a folder
         if (!file_exists($uploadPath)) {
             FileHelper::createDirectory($uploadPath, 0777, true);
         }
         //check for file with same name is exists
         $srcPath = $path . '/' . $file->name;
         $savePath = $uploadPath . '/' . $file->name;
         if (file_exists($savePath)) {
             $t = time();
             $savePath = $uploadPath . '/' . $t . "_" . $file->name;
             $srcPath = $path . '/' . $t . "_" . $file->name;
         }
         //move uploaded file and save it into database
         if ($file->saveAs($savePath)) {
             return Attachment::createNew($file, $srcPath);
         }
     }
     return false;
 }
开发者ID:Cranky4,项目名称:qwen23,代码行数:30,代码来源:File.php

示例10: actionInit

 public function actionInit()
 {
     $dir = Yii::getAlias('@app/rbac');
     if (!file_exists($dir)) {
         FileHelper::createDirectory($dir);
         echo 'RBAC configs dir was created.' . PHP_EOL;
     }
     /** @var BaseManager $authManager */
     $authManager = \Yii::$app->getModule('admin')->get('authManager');
     if ($this->confirm('Configure from role container?')) {
         /** @var Role[] $roles */
         $roles = \Yii::$app->getModule('admin')->get('roleContainer')->getRoles($authManager);
         foreach ($roles as $role) {
             $authManager->add($role);
         }
     } else {
         $file = Yii::getAlias('@app/config/admin_rbac.php');
         if (file_exists($file)) {
             include $file;
         } else {
             echo 'You must create file "@app/config/admin_rbac.php"' . PHP_EOL;
             //@TODO propose to create file
         }
     }
     echo 'RABC was configured' . PHP_EOL;
 }
开发者ID:NullRefExcep,项目名称:yii2-admin,代码行数:26,代码来源:RbacController.php

示例11: actionCreate

 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product(['scenario' => 'create']);
     $model->date = date('Y-m-d H:i');
     if ($model->load(Yii::$app->request->post())) {
         $model->image = UploadedFile::getInstance($model, 'image');
         $model->images = UploadedFile::getInstances($model, 'images');
         if ($model->validate() && $model->save() && $model->image) {
             // Working directory
             $dir = Yii::getAlias('@frontend/web/uploads/product/' . $model->id);
             FileHelper::createDirectory($dir);
             // Save main image
             $model->image->saveAs($dir . '/main.jpg');
             // Save images
             if ($model->images) {
                 foreach ($model->images as $image) {
                     $imageModel = new Image();
                     $imageModel->model_id = $model->id;
                     $imageModel->save();
                     $image->saveAs($dir . '/' . $imageModel->id . '.jpg');
                 }
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:cyanofresh,项目名称:yii2shop,代码行数:32,代码来源:ProductController.php

示例12: actionData

 public function actionData($file = false)
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     if (\Yii::$app->request->isPost) {
         /**@var Module $module */
         $module = Module::getInstance();
         $model = new DynamicModel(['file' => null]);
         $model->addRule('file', 'file', ['extensions' => $module->expansions, 'maxSize' => $module->maxSize]);
         $model->file = UploadedFile::getInstanceByName('image');
         if ($model->validate()) {
             if (!is_dir(\Yii::getAlias($module->uploadDir))) {
                 FileHelper::createDirectory(\Yii::getAlias($module->uploadDir));
             }
             $oldFileName = $model->file->name;
             $newFileName = $module->isFileNameUnique ? uniqid() . '.' . $model->file->extension : $oldFileName;
             $newFullFileName = \Yii::getAlias($module->uploadDir) . DIRECTORY_SEPARATOR . $newFileName;
             if ($model->file->saveAs($newFullFileName)) {
                 return ['id' => $oldFileName, 'url' => \Yii::$app->request->getHostInfo() . str_replace('@webroot', '', $module->uploadDir) . '/' . $newFileName];
             }
         } else {
             \Yii::$app->response->statusCode = 500;
             return $model->getFirstError('file');
         }
     } elseif (\Yii::$app->request->isDelete && $file) {
         return true;
     }
     throw new BadRequestHttpException();
 }
开发者ID:Hector68,项目名称:yii2-grafikart-markdown-editor,代码行数:28,代码来源:UploadController.php

示例13: up

 public function up()
 {
     // Creates folders for media manager
     $webroot = Yii::getAlias('@app/web');
     foreach (['upload', 'files'] as $folder) {
         $path = $webroot . '/' . $folder;
         if (!file_exists($path)) {
             echo "mkdir('{$path}', 0777)...";
             if (mkdir($path, 0777, true)) {
                 echo "done.\n";
             } else {
                 echo "failed.\n";
             }
         }
     }
     // Creates the default platform config
     /** @var \gromver\platform\basic\console\modules\main\Module $main */
     $cmf = Yii::$app->grom;
     $paramsPath = Yii::getAlias($cmf->paramsPath);
     $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php';
     $params = $cmf->params;
     $model = new \gromver\models\ObjectModel(\gromver\platform\basic\modules\main\models\PlatformParams::className());
     $model->setAttributes($params);
     echo 'Setup application config: ' . PHP_EOL;
     $this->readStdinUser('Site Name (My Site)', $model, 'siteName', 'My Site');
     $this->readStdinUser('Admin Email (admin@email.com)', $model, 'adminEmail', 'admin@email.com');
     $this->readStdinUser('Support Email (support@email.com)', $model, 'supportEmail', 'support@email.com');
     if ($model->validate()) {
         \yii\helpers\FileHelper::createDirectory($paramsPath);
         file_put_contents($paramsFile, '<?php return ' . var_export($model->toArray(), true) . ';');
         @chmod($paramsFile, 0777);
     }
     echo 'Setup complete.' . PHP_EOL;
 }
开发者ID:gromver,项目名称:yii2-platform-basic,代码行数:34,代码来源:m140820_085041_grom_site_setup.php

示例14: setUp

 protected function setUp()
 {
     parent::setUp();
     FileHelper::createDirectory($this->getParam('components')['assetManager']['basePath']);
     file_put_contents(__DIR__ . '/runtime/compress.html', '');
     $this->mock_application();
 }
开发者ID:switchy,项目名称:yii2-minify-view,代码行数:7,代码来源:TestCase.php

示例15: getImage

 /**
  *  fetch image from protected location and manipulate it and copy to public folder to show in front-end
  *  This function cache the fetched image with same width and height before
  * 
  * @author A.Jafaripur <mjafaripur@yahoo.com>
  * 
  * @param integer $id image id number to seprate the folder in public folder
  * @param string $path original image path
  * @param float $width width of image for resize
  * @param float $heigh height of image for resize
  * @param integer $quality quality of output image
  * @return string fetched image url
  */
 public function getImage($id, $path, $width, $heigh, $quality = 70)
 {
     $fileName = $this->getFileName(Yii::getAlias($path));
     $fileNameWithoutExt = $this->getFileNameWithoutExtension($fileName);
     $ext = $this->getFileExtension($fileName);
     if ($width == 0 && $heigh == 0) {
         $size = Image::getImagine()->open($path)->getSize();
         $width = $size->getWidth();
         $heigh = $size->getHeight();
     }
     $newFileName = $fileNameWithoutExt . 'x' . $width . 'w' . $heigh . 'h' . '.' . $ext;
     $upload_number = (int) ($id / 2000) + 1;
     $savePath = Yii::getAlias('@webroot/images/' . $upload_number);
     $baseImageUrl = Yii::$app->getRequest()->getBaseUrl() . '/images/' . $upload_number;
     FileHelper::createDirectory($savePath);
     $savePath .= DIRECTORY_SEPARATOR . $newFileName;
     if ($width == 0 && $heigh == 0) {
         copy($path, $savePath);
     } else {
         if (!file_exists($savePath)) {
             Image::thumbnail($path, $width, $heigh)->interlace(\Imagine\Image\ImageInterface::INTERLACE_PLANE)->save($savePath, ['quality' => $quality]);
         }
     }
     return $baseImageUrl . '/' . $newFileName;
 }
开发者ID:rocketyang,项目名称:admap,代码行数:38,代码来源:ImageHelper.php


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