本文整理汇总了PHP中yii\helpers\BaseFileHelper::removeDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseFileHelper::removeDirectory方法的具体用法?PHP BaseFileHelper::removeDirectory怎么用?PHP BaseFileHelper::removeDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\BaseFileHelper
的用法示例。
在下文中一共展示了BaseFileHelper::removeDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attachFile
public function attachFile()
{
try {
$model = $this->owner;
$fileName = Inflector::slug($model->fullAddress) . '.pdf';
$folder = $this->getModelSubDir() . '/';
$model->pdf_path = $fileName;
$pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'destination' => Pdf::DEST_FILE, 'content' => Yii::$app->view->render('@frontend/views/site/real-estate/print', ['model' => $model]), 'methods' => ['SetHeader' => ['Rapport ' . $model->fullAddress], 'SetFooter' => ['|Pagina {PAGENO}|']], 'filename' => Yii::getAlias('@uploadsBasePath') . "/files/{$folder}{$fileName}"]);
$this->file = $pdf;
BaseFileHelper::removeDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}");
if (!BaseFileHelper::createDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}")) {
throw new Exception(Yii::t('app', 'Failed to create the file upload directory'));
}
// Save and update model
$pdf->render();
$model->save();
return true;
} catch (yii\base\Exception $e) {
return $e->getMessage();
}
}
示例2: delPhotos
public static function delPhotos($sale_id)
{
$model = self::findAll(['sale_id' => $sale_id]);
foreach ($model as $item) {
$item->delete();
}
$path = Yii::$app->params['uploadSalePath'] . DIRECTORY_SEPARATOR . $sale_id;
BaseFileHelper::removeDirectory($path);
}
示例3: clearCache
public function clearCache()
{
$subDir = $this->getSubDur();
$dirToRemove = $this->getModule()->getCachePath() . DIRECTORY_SEPARATOR . $subDir;
if (preg_match('/' . preg_quote($this->modelName, '/') . DIRECTORY_SEPARATOR, $dirToRemove)) {
BaseFileHelper::removeDirectory($dirToRemove);
}
return true;
}
示例4: flushPublishedCopies
/**
* @return static
*/
public function flushPublishedCopies()
{
$module = $this->getModule();
$subDirectory = $this->getSubDirectory();
$dirToRemove = "{$module->publishPath}{$module->ds}{$subDirectory}";
$quotedModelName = preg_quote($this->modelName, '/');
if (preg_match("@{$quotedModelName}@", $dirToRemove)) {
BaseFileHelper::removeDirectory($dirToRemove);
}
return $this;
}
示例5: attachFile
public function attachFile()
{
try {
$model = $this->owner;
$model->file = UploadedFile::getInstance($model, 'file');
if ($model->validate() && $model->file) {
$fileName = Inflector::slug($model->file->baseName) . '.' . $model->file->extension;
$folder = $this->getModelSubDir() . '/';
$model->path = $fileName;
BaseFileHelper::removeDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}");
if (!BaseFileHelper::createDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}")) {
throw new Exception(Yii::t('app', 'Failed to create the file upload directory'));
}
$model->file->saveAs(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}{$model->path}");
$model->save();
}
return true;
} catch (yii\base\Exception $e) {
return $e->getMessage();
}
}
示例6: clearImagesCache
/**
* Clear all images cache (and resized copies)
* @return bool
*/
public function clearImagesCache()
{
$cachePath = $this->getModule()->getCachePath();
$subdir = $this->getModule()->getModelSubDir($this->owner);
$dirToRemove = $cachePath . '/' . $subdir;
if (preg_match('/' . preg_quote($cachePath, '/') . '/', $dirToRemove)) {
BaseFileHelper::removeDirectory($dirToRemove);
//exec('rm -rf ' . $dirToRemove);
return true;
} else {
return false;
}
}
示例7: afterDelete
public function afterDelete()
{
SalePhoto::delPhotos($this->id);
$path = Yii::$app->params['uploadSalePath'] . DIRECTORY_SEPARATOR . $this->id;
BaseFileHelper::removeDirectory($path);
if (!self::findOne(['object_id' => $this->object_id])) {
Object::findOne($this->object_id)->delete();
}
return parent::afterDelete();
}
示例8: removeUploadDir
private function removeUploadDir($dir)
{
BaseFileHelper::removeDirectory(Album::getUploadPath() . $dir);
}
示例9: clearAll
/**
* Remove all cached images
*/
public function clearAll()
{
@BaseFileHelper::removeDirectory($this->sourcePath . $this->cachePath . '/imagecache/');
}
示例10: removeUploadDir
private function removeUploadDir($dir)
{
BaseFileHelper::removeDirectory(PhotoLibrary::getUploadPath() . $dir);
}
示例11: removeItemFolder
public function removeItemFolder($related, $itemId)
{
$uploadPath = $this->routes['uploadPath'];
$uploadPath .= '/' . $related;
$structure = "{$this->routes['baseUrl']}/{$uploadPath}";
$basePath = Yii::getAlias($this->routes['basePath']);
$dir = "{$basePath}{$structure}/{$itemId}";
\yii\helpers\BaseFileHelper::removeDirectory($dir);
}
示例12: beforeDelete
public function beforeDelete()
{
if (parent::beforeDelete()) {
ActivityImage::deleteAll(['id_activity' => $this->id]);
BaseFileHelper::removeDirectory(Yii::getAlias('@activity/') . $this->id);
return true;
} else {
return false;
}
}
示例13: actionIntegration
public function actionIntegration()
{
$dsn_array_attribute = explode('=', Yii::$app->db->dsn);
$db_name = $dsn_array_attribute[2];
$table_prefix = Yii::$app->db->tablePrefix;
BaseFileHelper::createDirectory($this->tempDir, 0777);
foreach ($this->files as $table_name => $filename) {
$zip_name = $this->tempDir . $filename;
if (!file_exists($zip_name)) {
if (!($tmp_file = fopen($zip_name, 'w'))) {
return;
}
$curl = curl_init();
$url = $this->baseUrl . $filename;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FILE, $tmp_file);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_exec($curl);
curl_close($curl);
fclose($tmp_file);
}
if (preg_match('/\\.zip$/', $zip_name)) {
$zip = new \ZipArchive();
$zip->open($zip_name);
$zip->extractTo($this->tempDir);
}
$unziped_name = str_replace('.zip', '.txt', $zip_name);
if ($table_name == 'geoname_alternative_name') {
$new_unzipped_name = $this->tempDir . 'ru_names.txt';
`grep -P '^\\d+\t\\d+\tru\t' {$unziped_name} > {$new_unzipped_name}`;
$unziped_name = $new_unzipped_name;
} else {
if ($table_name == 'geoname_country') {
$new_unzipped_name = $this->tempDir . 'countryInfo_fixed.txt';
`grep -Pv '^#.*\$' {$unziped_name} > {$new_unzipped_name}`;
$unziped_name = $new_unzipped_name;
}
}
$fields = ArrayHelper::getColumn(Yii::$app->db->createCommand("SHOW COLUMNS FROM {$table_prefix}{$table_name}")->query(), 'Field');
Yii::$app->db->createCommand("TRUNCATE {$table_prefix}{$table_name}")->query();
$sql = "LOAD DATA LOCAL INFILE '" . $unziped_name . "' INTO TABLE " . $table_prefix . $table_name . ' CHARACTER SET utf8 FIELDS TERMINATED BY \\"\\t\\" LINES TERMINATED BY \\"\\n\\" (' . implode(', ', $fields) . ')';
$db = Yii::$app->db;
$cmd = "mysql --local-infile=1 -u{$db->username} -p{$db->password} {$db_name} -e \"{$sql}\" \n";
`{$cmd}`;
}
BaseFileHelper::removeDirectory($this->tempDir);
Yii::$app->db->createCommand("DELETE FROM {$table_prefix}geoname_country WHERE geoname_id = 0")->query();
$sql = "SELECT {$table_prefix}geoname_country.*,\n (SELECT alternate_name FROM {$table_prefix}geoname_alternative_name WHERE {$table_prefix}geoname_alternative_name.geoname_id = {$table_prefix}geoname_country.geoname_id LIMIT 0,1) as ru_name\n FROM {$table_prefix}geoname_country ";
$geoname_countries = Yii::$app->db->createCommand($sql)->query();
foreach ($geoname_countries as $geoname_country) {
if (!($country = Country::findOne(['iso' => $geoname_country['iso']]))) {
$country = new Country();
}
$attributes = ['iso' => $geoname_country['iso'], 'title' => $geoname_country['ru_name'], 'worldpart' => $geoname_country['continent'], 'geoname_id' => $geoname_country['geoname_id'], 'is_published' => 1];
if (!$country->getIsNewRecord()) {
$attributes = ['geoname_id' => $geoname_country['geoname_id']];
}
$capital_id = $this->getCapitalIdByName($geoname_country['capital'], $geoname_country['iso'], $table_prefix);
if ($capital_id && $country->capital_id != $capital_id) {
$attributes['capital_id'] = $capital_id;
}
$country->setAttributes($attributes);
$country->save();
}
$country_ids = [];
foreach (Yii::$app->db->createCommand("SELECT id, iso FROM {$table_prefix}country")->query() as $item) {
$country_ids[$item['iso']] = $item['id'];
}
$sql = "SELECT\n {$table_prefix}geoname_city.geoname_id as geoname_id,\n {$table_prefix}geoname_city.alternate_names as alternate_names,\n {$table_prefix}geoname_city.latitude as latitude,\n {$table_prefix}geoname_city.longitude as longitude,\n {$table_prefix}geoname_city.country_code as country_code,\n {$table_prefix}geoname_alternative_name.alternate_name as ru_name\n FROM {$table_prefix}geoname_city\n JOIN {$table_prefix}geoname_alternative_name ON {$table_prefix}geoname_alternative_name.geoname_id = {$table_prefix}geoname_city.geoname_id\n GROUP BY geoname_id ";
$geoname_cities = Yii::$app->db->createCommand($sql)->query();
foreach ($geoname_cities as $geoname_city) {
if (!$geoname_city['country_code']) {
continue;
}
if (!isset($country_ids[$geoname_city['country_code']])) {
continue;
}
if (!$geoname_city['geoname_id']) {
continue;
}
$russian_city_title = trim($geoname_city['ru_name']);
$russian_city_title = mb_convert_case($russian_city_title, MB_CASE_TITLE, 'UTF-8');
if (!preg_match('/[а-яА-я]/', $russian_city_title)) {
continue;
}
if (!($city = City::findOne(['geoname_id' => $geoname_city['geoname_id']]))) {
$city = new City();
}
$identifier = strtolower($this->translitRussian($russian_city_title));
$identifier = str_replace(' ', ' ', $identifier);
$identifier = str_replace(' ', '-', $identifier);
$attributes = ['title' => $russian_city_title, 'latitude' => $geoname_city['latitude'], 'longitude' => $geoname_city['longitude'], 'identifier' => $identifier, 'geoname_id' => $geoname_city['geoname_id'], 'country_id' => $country_ids[$geoname_city['country_code']], 'is_published' => 1];
if (!$city->getIsNewRecord()) {
unset($attributes['title']);
unset($attributes['identifier']);
unset($attributes['country_id']);
unset($attributes['is_published']);
}
$city->setAttributes($attributes);
$city->save();
//.........这里部分代码省略.........
示例14: removeUploadDir
private function removeUploadDir($dir)
{
BaseFileHelper::removeDirectory(Employee::getUploadPath() . '/' . $dir);
}
示例15: removePhotosUploadDir
private function removePhotosUploadDir($dir)
{
BaseFileHelper::removeDirectory(Article::getUploadPhotosPath() . $dir);
}