本文整理匯總了PHP中HFile::getDir方法的典型用法代碼示例。如果您正苦於以下問題:PHP HFile::getDir方法的具體用法?PHP HFile::getDir怎麽用?PHP HFile::getDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HFile
的用法示例。
在下文中一共展示了HFile::getDir方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getCopyFileName
protected function getCopyFileName($filePath)
{
$path = HFile::getDir($filePath);
$files = file_exists($path) ? HFile::findFiles($path) : array();
$files = array_flip($files);
$ext = HFile::getExtension($this->fileName);
$file = HFile::getFileNameByPath($this->fileName, true);
$i = 0;
$copyFileName = '';
do {
$copyFileName = $file . '(' . ++$i . ').' . $ext;
} while (array_key_exists($copyFileName, $files));
return $copyFileName;
}
示例2: combineAndCompress
/**
* Performs the actual combining and compressing
*
* @param <type> $type
* @param <type> $urls
* @param <type> $pos
*/
private function combineAndCompress($type, $urls, $pos)
{
$this->fileUrl or $this->fileUrl = $this->getCoreScriptUrl();
$this->basePath or $this->basePath = realpath($_SERVER['DOCUMENT_ROOT']);
$this->filePath or $this->filePath = $this->basePath . $this->fileUrl;
$optionsHash = $type == 'js' ? md5($this->basePath . $this->compressJs . $this->ttlDays . $this->prefix) : md5($this->basePath . $this->compressCss . $this->ttlDays . $this->prefix . serialize($this->cssMinFilters + $this->cssMinPlugins));
if ($this->autoRefresh) {
$mtimes = array();
foreach ($urls as $file) {
$fileName = $this->basePath . '/' . trim($file, '/');
if (file_exists($fileName)) {
$mtimes[] = filemtime($fileName);
}
}
$this->_changesHash = md5(serialize($mtimes));
}
$combineHash = md5(implode('', $urls));
$fileName = $this->prefix . md5($combineHash . $optionsHash . $this->_changesHash) . ".{$type}";
$this->_renewFile = file_exists($this->filePath . '/' . $fileName) ? false : true;
if ($this->_renewFile) {
$this->garbageCollect($type);
$combinedFile = '';
$notCompress = '';
// mixa
foreach ($urls as $key => $file) {
$path = str_replace('//', '/', $this->basePath . '/' . $file);
if (!file_exists($path) && mb_strpos($path, Yii::app()->assetManager->basePath) !== false) {
// TODO тестовая версия
$dir = HFile::getDir($path);
HFile::removeDirectoryRecursive($dir);
Yii::app()->getRequest()->redirect(Yii::app()->getRequest()->getUrl());
}
$fileContent = file_get_contents($path);
// mixa, обработка зависимых файлов
$fn = basename($file);
if (isset($this->dependResource[$fn])) {
$webroot = Yii::getPathOfAlias('webroot');
foreach ($this->dependResource[$fn] as $dependFile => $addPath) {
$dependFile = str_replace('\\', '/', $dependFile);
$dependFileName = basename($dependFile);
$relativePath = str_replace($webroot, "", $dependFile);
if (!file_exists($this->filePath . $relativePath)) {
$dir = dirname($this->filePath . $relativePath);
if (!file_exists($dir)) {
mkdir($dir, Yii::app()->assetManager->newDirMode, true);
}
copy($dependFile, $this->filePath . $relativePath);
@chmod($this->filePath . '/' . $dependFileName, Yii::app()->assetManager->newFileMode);
}
// $fileContent = str_replace($addPath.$dependFileName, $this->fileUrl.$relativePath, $fileContent);
$fileContent = preg_replace('~([^a-zA-Z\\-])' . $addPath . $dependFileName . '~u', "\${1}" . $this->fileUrl . $relativePath, $fileContent);
}
}
//---
if ($type == 'css' && strpos($fn, ".min") !== false) {
// mixa, почему-то уже сжатые css-файлы жмутся с ошибками (bootstrap)
$notCompress .= $fileContent;
} else {
$combinedFile .= $fileContent;
if ($type == 'js') {
$combinedFile .= ";\n\r";
}
}
}
if ($type == 'js' && $this->compressJs) {
$combinedFile = $this->minifyJs($combinedFile);
}
if ($type == 'css' && $this->compressCss) {
$combinedFile = $this->minifyCss($combinedFile);
}
file_put_contents($this->filePath . '/' . $fileName, $notCompress . $combinedFile);
}
foreach ($urls as $url) {
$this->scriptMap[basename($url)] = $this->fileUrl . '/' . $fileName;
}
$this->remapScripts();
}
示例3: beforeDelete
protected function beforeDelete()
{
//Рекурсивно удаляем дочерние файлы:
$this->deleteChildFile();
//Удаляем файл:
HFile::removeFile($this->getFilePath());
//Удаляем папку где был файл (если пустая)
HFile::removeDir(HFile::getDir($this->getFilePath()));
return parent::beforeDelete();
}