本文整理汇总了PHP中CFileHelper类的典型用法代码示例。如果您正苦于以下问题:PHP CFileHelper类的具体用法?PHP CFileHelper怎么用?PHP CFileHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFileHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _installExampleTemplates
/**
* Install templates
*
* @return void
*/
private function _installExampleTemplates()
{
try {
$fileHelper = new \CFileHelper();
@mkdir(craft()->path->getSiteTemplatesPath() . 'sproutemail');
$fileHelper->copyDirectory(craft()->path->getPluginsPath() . 'sproutemail/templates/_special/examples/emails', craft()->path->getSiteTemplatesPath() . 'sproutemail');
} catch (\Exception $e) {
$this->_handleError($e);
}
}
示例2: run
public function run($args = null)
{
$theme = $args[0];
$themePath = realpath(dirname(__FILE__) . '/../../themes') . DIRECTORY_SEPARATOR . $theme;
if (!file_exists($themePath)) {
mkdir($themePath);
mkdir($themePath . '/views');
}
// Find all modules views and copy to theme directory
$files = glob(realpath(dirname(__FILE__) . '/../') . '/modules/*', GLOB_ONLYDIR);
foreach ($files as $file) {
$parts = explode('/', $file);
$module = end($parts);
$moduleThemePath = $themePath . '/views/' . $module;
$moduleViews = glob($file . '/views/*', GLOB_ONLYDIR);
foreach ($moduleViews as $viewsDirPath) {
$parts = explode('/', $viewsDirPath);
if (end($parts) != 'admin') {
if (!file_exists($moduleThemePath)) {
mkdir($moduleThemePath);
}
CFileHelper::copyDirectory($viewsDirPath, $moduleThemePath . '/' . end($parts));
}
}
}
}
示例3: run
public function run($args = null)
{
$theme = $args[0];
$themePath = realpath(dirname(__FILE__) . '/../../themes') . '/' . $theme;
if (!file_exists($themePath)) {
mkdir($themePath);
mkdir($themePath . '/views');
}
// Find all modules views and copy to theme directory
$files = glob(realpath(dirname(__FILE__) . '/../') . '/modules/*', GLOB_ONLYDIR);
foreach ($files as $file) {
$parts = explode('/', $file);
$module = end($parts);
// Don't copy next modules to theme dir.
if (in_array($module, array('admin', 'install', 'rights'))) {
continue;
}
$moduleThemePath = $themePath . '/views/' . $module;
$moduleViews = glob($file . '/views/*', GLOB_ONLYDIR);
foreach ($moduleViews as $viewsDirPath) {
$parts = explode('/', $viewsDirPath);
if (end($parts) != 'admin') {
if (!file_exists($moduleThemePath)) {
mkdir($moduleThemePath, 0777, true);
}
CFileHelper::copyDirectory($viewsDirPath, $moduleThemePath . '/' . end($parts));
}
}
}
}
示例4: getModels
protected function getModels()
{
$models = array();
$files = scandir(Yii::getPathOfAlias('application.models'));
foreach ($files as $file) {
if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
$fileClassName = substr($file, 0, strpos($file, '.'));
if (class_exists($fileClassName) && is_subclass_of($fileClassName, 'GiiyActiveRecord')) {
$fileClass = new ReflectionClass($fileClassName);
if (!$fileClass->isAbstract() && !is_array(GiiyActiveRecord::model($fileClassName)->getPrimaryKey())) {
$models[] = $fileClassName;
}
}
}
}
foreach (Yii::app()->getModules() as $module => $moduleConf) {
if (Yii::getPathOfAlias($module . '.models')) {
$files = scandir(Yii::getPathOfAlias($module . '.models'));
foreach ($files as $file) {
if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
$fileClassName = substr($file, 0, strpos($file, '.'));
if (class_exists($fileClassName) && is_subclass_of($fileClassName, 'GiiyActiveRecord')) {
$fileClass = new ReflectionClass($fileClassName);
if (!$fileClass->isAbstract() && !is_array(GiiyActiveRecord::model($fileClassName)->getPrimaryKey())) {
$models[] = $fileClassName;
}
}
}
}
}
}
return $models;
}
示例5: prepare
public function prepare()
{
$this->files = array();
$templatePath = $this->templatePath;
$modulePath = $this->modulePath;
$moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
$this->files[] = new CCodeFile($modulePath . '/' . $this->moduleClass . '.php', $this->render($moduleTemplateFile));
$files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
foreach ($files as $file) {
if ($file !== $moduleTemplateFile && !$this->isIgnireFile($file)) {
if (CFileHelper::getExtension($file) === 'php') {
$content = $this->render($file);
} elseif (basename($file) === '.gitkeep') {
$file = dirname($file);
$content = null;
} else {
$content = file_get_contents($file);
}
$modifiedFile = $this->getModifiedFile($file);
if ($modifiedFile !== false) {
$file = $modifiedFile;
}
$this->files[] = new CCodeFile($modulePath . substr($file, strlen($templatePath)), $content);
}
}
}
示例6: prepare
public function prepare()
{
$this->files = array();
$templatePath = $this->templatePath;
$modulePath = $this->modulePath;
$moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
$this->files[] = new CCodeFile($modulePath . '/' . $this->moduleClass . '.php', $this->render($moduleTemplateFile));
$files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn')));
foreach ($files as $file) {
if ($file !== $moduleTemplateFile) {
if (CFileHelper::getExtension($file) === 'php') {
$content = $this->render($file);
} else {
if (basename($file) === '.yii') {
// an empty directory
$file = dirname($file);
$content = null;
} else {
$content = file_get_contents($file);
}
}
$this->files[] = new CCodeFile($modulePath . substr($file, strlen($templatePath)), $content);
}
}
}
示例7: run
public function run($attr)
{
$name = strtolower($this->getController()->getId());
$attribute = strtolower((string) $attr);
if ($this->uploadPath === null) {
$path = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'uploads';
$this->uploadPath = realpath($path);
if ($this->uploadPath === false) {
exit;
}
}
if ($this->uploadUrl === null) {
$this->uploadUrl = Yii::app()->request->baseUrl . '/uploads';
}
$attributePath = $this->uploadPath . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . $attribute;
$attributeUrl = $this->uploadUrl . '/' . $name . '/' . $attribute . '/';
$files = CFileHelper::findFiles($attributePath, array('fileTypes' => array('gif', 'png', 'jpg', 'jpeg')));
$data = array();
if ($files) {
foreach ($files as $file) {
$data[] = array('thumb' => $attributeUrl . basename($file), 'image' => $attributeUrl . basename($file));
}
}
echo CJSON::encode($data);
exit;
}
示例8: afterSave
public function afterSave($event)
{
if (!empty($_FILES)) {
$model = $this->getOwner();
$file = new File();
$file->filename = UploadUtils::createUniquefilename($_FILES[self::NAME]['name'], UploadUtils::getPath(self::$fileDir));
if (move_uploaded_file($_FILES[self::NAME]['tmp_name'], UploadUtils::getPath(self::$fileDir) . DIRECTORY_SEPARATOR . $file->filename)) {
$file->entity = get_class($model);
$file->EXid = $model->getPrimaryKey();
$file->uid = Yii::app()->user->id;
$file->tag = $this->tag;
$file->weight = 0;
$file->timestamp = time();
$file->filemime = CFileHelper::getMimeTypeByExtension($_FILES[self::NAME]['name']);
$file->filesize = $_FILES[self::NAME]['size'];
$file->status = File::STATUS_SAVED;
// Ensure all other files of the entity are deleted
//UploadUtils::deleteAllFiles(get_class($this->getOwner()), self::$fileDir);
if ($file->save()) {
Yii::trace("File saved " . $file . "!!!!");
} else {
Yii::log("Could not save File " . print_r($file->getErrors(), true), CLogger::LEVEL_ERROR);
}
} else {
Yii::log("Couldnt move the file", CLogger::LEVEL_ERROR);
}
} else {
Yii::log("Files empty!!!", CLogger::LEVEL_ERROR);
}
}
示例9: 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);
}
示例10: up
public function up()
{
CFileHelper::removeDirectory(Yii::app()->basePath . "/components/dashboard/");
CFileHelper::removeDirectory(Yii::app()->basePath . "/../update/");
CFileHelper::removeDirectory(Yii::app()->basePath . "/../assets/lib/chosen/");
$this->update('openformat', array("export" => "this.reg_date", "import" => 'this.reg_date'), "id='1362'");
}
示例11: actionGet
public function actionGet()
{
$dir = Yii::getPathOfAlias(Yii::app()->params['sharedMemory']['flushDirectory']);
$files = CFileHelper::findFiles($dir, array('fileTypes' => array(Yii::app()->params['sharedMemory']['flushExtension'])));
if (isset($files[0])) {
$size = filesize($files[0]);
$file = fopen($files[0], 'r');
$descriptor = $files[0] . ".descr";
if (is_file($descriptor)) {
$descr = fopen($descriptor, "r");
$pos = fread($descr, filesize($descriptor));
fclose($descr);
} else {
$pos = 0;
}
fseek($file, $pos);
$content = fread($file, self::CHUNK_SIZE);
$position = strrpos($content, '##') + 2;
$pos += $position;
echo substr($content, 0, $position);
fclose($file);
$descr = fopen($descriptor, "w");
fwrite($descr, $pos);
fclose($descr);
if ($pos >= $size) {
unlink($files[0]);
unlink($descriptor);
}
Yii::app()->end();
}
}
示例12: actionUpload
/**
* Feltölt egy fájlt a megadott tantárgyhoz.
* @param int $id A tantárgy azonosítója
*/
public function actionUpload($id)
{
if (!Yii::app()->user->getId()) {
throw new CHttpException(403, 'A funkció használatához be kell jelentkeznie');
}
$id = (int) $id;
$file = CUploadedFile::getInstanceByName("to_upload");
if ($file == null) {
throw new CHttpException(404, 'Nem lett fájl kiválasztva a feltöltéshez');
}
$filename = $file->getName();
$localFileName = sha1($filename . microtime()) . "." . CFileHelper::getExtension($filename);
if (in_array(strtolower(CFileHelper::getExtension($filename)), Yii::app()->params["deniedexts"])) {
throw new CHttpException(403, ucfirst(CFileHelper::getExtension($filename)) . ' kiterjesztésű fájl nem tölthető fel a szerverre');
}
$model = new File();
$model->subject_id = $id;
$model->filename_real = $filename;
$model->filename_local = $localFileName;
$model->description = htmlspecialchars($_POST["description"]);
$model->user_id = Yii::app()->user->getId();
$model->date_created = new CDbExpression('NOW()');
$model->date_updated = new CDbExpression('NOW()');
$model->downloads = 0;
$model->save();
if ($file->saveAs("upload/" . $localFileName)) {
$this->redirect(Yii::App()->createUrl("file/list", array("id" => $id)));
}
}
示例13: actionImagelist
public function actionImagelist($attr)
{
$attribute = strtolower($attr);
$uploadPath = Yii::app()->basePath . '/../images';
$uploadUrl = bu('images');
if ($uploadPath === null) {
$path = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'uploads';
$uploadPath = realpath($path);
if ($uploadPath === false) {
exit;
}
}
if ($uploadUrl === null) {
$uploadUrl = Yii::app()->request->baseUrl . '/uploads';
}
$attributePath = $uploadPath . DIRECTORY_SEPARATOR . $attribute;
$attributeUrl = $uploadUrl . '/' . $attribute . '/';
$files = CFileHelper::findFiles($attributePath, array('fileTypes' => array('gif', 'png', 'jpg', 'jpeg'), 'level' => 0));
$data = array();
if ($files) {
foreach ($files as $file) {
$data[] = array('thumb' => $attributeUrl . basename($file), 'image' => $attributeUrl . basename($file));
}
}
echo CJSON::encode($data);
exit;
}
示例14: actionIndex
public function actionIndex($path = null, $fix = null)
{
if ($path === null) {
$path = YII_PATH;
}
echo "Checking {$path} for files with BOM.\n";
$checkFiles = CFileHelper::findFiles($path, array('exclude' => array('.gitignore')));
$detected = false;
foreach ($checkFiles as $file) {
$fileObj = new SplFileObject($file);
if (!$fileObj->eof() && false !== strpos($fileObj->fgets(), self::BOM)) {
if (!$detected) {
echo "Detected BOM in:\n";
$detected = true;
}
echo $file . "\n";
if ($fix) {
file_put_contents($file, substr(file_get_contents($file), 3));
}
}
}
if (!$detected) {
echo "No files with BOM were detected.\n";
} else {
if ($fix) {
echo "All files were fixed.\n";
}
}
}
示例15: run
/**
* Execute the action.
* @param array command line parameters specific for this command
*/
public function run($args)
{
if (!isset($args[0])) {
$this->usageError('the CLDR data directory is not specified.');
}
if (!is_dir($path = $args[0])) {
$this->usageError("directory '{$path}' does not exist.");
}
// collect XML files to be processed
$options = array('exclude' => array('.svn'), 'fileTypes' => array('xml'), 'level' => 0);
$files = CFileHelper::findFiles(realpath($path), $options);
$sourceFiles = array();
foreach ($files as $file) {
$sourceFiles[basename($file)] = $file;
}
// sort by file name so that inheritances can be processed properly
ksort($sourceFiles);
// process root first because it is inherited by all
if (isset($sourceFiles['root.xml'])) {
$this->process($sourceFiles['root.xml']);
unset($sourceFiles['root.xml']);
foreach ($sourceFiles as $sourceFile) {
$this->process($sourceFile);
}
} else {
die('Unable to find the required root.xml under CLDR data directory.');
}
}