本文整理汇总了PHP中yii\helpers\BaseFileHelper类的典型用法代码示例。如果您正苦于以下问题:PHP BaseFileHelper类的具体用法?PHP BaseFileHelper怎么用?PHP BaseFileHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseFileHelper类的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: createCachedFile
/**
* @param $srcImagePath
* @param bool $preset
* @return string Path to cached file
* @throws \Exception
*/
private function createCachedFile($srcImagePath, $pathToSave, $size = null)
{
BaseFileHelper::createDirectory(dirname($pathToSave), 0777, true);
$size = $size ? $this->parseSize($size) : false;
// if($this->graphicsLibrary == 'Imagick'){
$image = new \Imagick($srcImagePath);
$image->setImageCompressionQuality(100);
if ($size) {
if ($size['height'] && $size['width']) {
$image->cropThumbnailImage($size['width'], $size['height']);
} elseif ($size['height']) {
$image->thumbnailImage(0, $size['height']);
} elseif ($size['width']) {
$image->thumbnailImage($size['width'], 0);
} else {
throw new \Exception('Error at $this->parseSize($sizeString)');
}
}
$image->writeImage($pathToSave);
// }
if (!is_file($pathToSave)) {
throw new \Exception('Error while creating cached file');
}
return $image;
}
示例3: upload
public function upload($upload_dir = 'product_image')
{
$file_name = [];
if ($this->validate()) {
$app_root = Yii::getAlias('@approot');
$upload_path = "{$app_root}/uploads/{$upload_dir}/";
if (!file_exists($upload_path)) {
BaseFileHelper::createDirectory($upload_path, 0777, TRUE);
} else {
if (!is_dir($upload_path)) {
unlink($upload_path);
$this->upload($upload_dir);
}
}
foreach ($this->imageFiles as $file) {
$file_path = "{$upload_path}{$file->baseName}.{$file->extension}";
$file->saveAs($file_path);
$file_info['name'] = 'product_image';
$file_info['type'] = $file->type;
$file_info['value'] = $file->baseName . '.' . $file->extension;
$file_name[] = $file_info;
}
return $file_name;
} else {
return false;
}
}
示例4: cacheDir
private function cacheDir()
{
$dir = Yii::getAlias(self::$cache_dir);
if (!file_exists($dir)) {
BaseFileHelper::createDirectory($dir, '0755');
}
return $dir;
}
示例5: 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);
}
示例6: generateModul
public function generateModul()
{
BaseFileHelper::createDirectory($this->moduleDirectory, 509, true);
$content = $this->modulInner();
$moduleFullName = $this->moduleDirectory . $this->moduleName . '.php';
$myFail = fopen($moduleFullName, "w");
fwrite($myFail, $content);
fclose($myFail);
return true;
}
示例7: bootstrap
/** @inheritdoc */
public function bootstrap($app)
{
/* Config Translation */
if (!isset($app->get('i18n')->translations['adminlte*'])) {
$app->get('i18n')->translations['adminlte*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
}
/* Config Theme */
if (!isset($app->view->theme)) {
$app->view->theme = new \yii\base\Theme(['pathMap' => ['@app/views/layouts' => '@cjtterabytesoft/adminlte/basic/views/layouts', '@app/views/site' => '@cjtterabytesoft/adminlte/basic/views/site']]);
}
/* Copy Avatar Images */
if (\yii\helpers\BaseFileHelper::filterPath(\Yii::getAlias('@app/web/images'), $options = [])) {
\yii\helpers\BaseFileHelper::copyDirectory(\Yii::getAlias('@cjtterabytesoft/adminlte/basic/images/'), \Yii::getAlias('@app/web/images'));
}
/* Config Params */
if (!isset($app->params['adminEmail'])) {
$app->params['adminEmail'] = 'admin@example.com';
}
if (!isset($app->params['AdminLTESkin'])) {
$app->params['AdminLTESkin'] = 'skin-yellow';
}
if (!isset($app->params['Author'])) {
$app->params['Author'] = '2015 - Wilmer Arambula';
}
if (!isset($app->params['Facebook_Account'])) {
$app->params['Facebook_Account'] = 'https://www.facebook.com/username';
}
if (!isset($app->params['Google_Account'])) {
$app->params['Google_Account'] = 'https://www.google.com/+username';
}
if (!isset($app->params['Linkedin_Account'])) {
$app->params['Linkedin_Account'] = 'https://www.linkedin.com/in/username';
}
if (!isset($app->params['Twitter_Account'])) {
$app->params['Twitter_Account'] = 'https://twitter.com/username';
}
if (!isset($app->params['WebName'])) {
$app->params['WebName'] = 'My Application';
}
if (!YII_ENV_TEST) {
if (!isset($app->params['imagesurl_30'])) {
$app->params['imagesurl_30'] = 'http://www.basic.tk/images/avatar/profile/30/icon-avatar.png';
}
if (!isset($app->params['imagesurl_60'])) {
$app->params['imagesurl_60'] = 'http://www.basic.tk/images/avatar/profile/60/icon-avatar.png';
}
} else {
if (!isset($app->params['imagesurl_30'])) {
$app->params['imagesurl_30'] = 'http://localhost.basic/images/avatar/profile/30/icon-avatar.png';
}
if (!isset($app->params['imagesurl_60'])) {
$app->params['imagesurl_60'] = 'http://localhost.basic/images/avatar/profile/60/icon-avatar.png';
}
}
}
示例8: actionUpdate
public function actionUpdate($id = null)
{
$model = new Article();
if ($model->load(Yii::$app->request->post())) {
$request = Yii::$app->request->post('Article');
$id = $request['id'];
if ($id) {
$model = Article::findOne($id);
$model->attributes = $request;
}
if ($model->save()) {
$this->updateOrder('cid=' . $model->cid, '&langs=' . $model->langs);
$files = \yii\web\UploadedFile::getInstances($model, 'upload_files');
if (isset($files) && count($files) > 0) {
$mPath = \Yii::getAlias('@webroot') . '/images/article/news_' . $model->id;
if (!is_dir($mPath)) {
\yii\helpers\BaseFileHelper::createDirectory($mPath);
}
foreach ($files as $file) {
if ($request['cid'] == '12') {
$mPic = $file->baseName . '.' . $file->extension;
} else {
$mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension;
}
//Upload Images
if ($file->saveAs($mPath . '/' . $mPic)) {
$image = \Yii::$app->image->load($mPath . '/' . $mPic);
$image->resize(1024, 1024);
$image->save($mPath . '/' . $mPic);
//resize images thumb
$image = \Yii::$app->image->load($mPath . '/' . $mPic);
$image->resize(250, 250);
$mThumb = $mPath . '/thumb/';
if (!is_dir($mThumb)) {
\yii\helpers\BaseFileHelper::createDirectory($mThumb);
}
$image->save($mThumb . $mPic);
}
}
}
return $this->redirect(array('index'));
} else {
print_r($model->getErrors());
exit;
}
}
if ($id) {
$model = Article::findOne($id);
} else {
$sess = Yii::$app->session->get('sessArticle');
$model->langs = $sess['langs'];
$model->cid = $sess['cid'];
}
return $this->render('update', ['model' => $model]);
}
示例9: 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;
}
示例10: getMimeType
public function getMimeType()
{
$extensions = $result = [];
foreach ($this->acceptedFilesType as $mimeType) {
$extensions[] = BaseFileHelper::getExtensionsByMimeType($mimeType);
}
foreach ($extensions as $ext) {
$result = \yii\helpers\ArrayHelper::merge($result, $ext);
}
return $result;
}
示例11: bootstrap
/** @inheritdoc */
public function bootstrap($app)
{
/* Config Translation */
if (!isset($app->get('i18n')->translations['adminlte*'])) {
$app->get('i18n')->translations['adminlte*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
}
/* Copy Avatar Images */
if (\yii\helpers\BaseFileHelper::filterPath(\Yii::getAlias('@frontend/web/images'), $options = [])) {
\yii\helpers\BaseFileHelper::copyDirectory(\Yii::getAlias('@cjtterabytesoft/adminlte/advanced/images/'), \Yii::getAlias('@frontend/web/images'));
}
}
示例12: attachImage
/**
* Copies the image to the assets folder and save's it in the database.
*
* @param string $absolutePath The path were the image is uploaded
* @param bool $isMain A flag to determine if the image is the main image
* @param string $identifier The index that has to be set for the image in the database
* @return bool|Image
* @throws \Exception
*/
public function attachImage($absolutePath, $isMain = false, $identifier = '')
{
if (!preg_match('#http#', $absolutePath)) {
if (!file_exists($absolutePath)) {
throw new \Exception('File not exist! :' . $absolutePath);
}
} else {
//nothing
}
if (!$this->owner->primaryKey) {
throw new \Exception('Owner must have primaryKey when you attach image!');
}
$pictureFileName = basename($absolutePath);
$pictureSubDir = $this->getModule()->getModelSubDir($this->owner);
$storePath = $this->getModule()->getStorePath($this->owner);
$newAbsolutePath = $storePath . DIRECTORY_SEPARATOR . $pictureSubDir . DIRECTORY_SEPARATOR . $pictureFileName;
BaseFileHelper::createDirectory($storePath . DIRECTORY_SEPARATOR . $pictureSubDir, 0775, true);
copy($absolutePath, $newAbsolutePath);
unlink($absolutePath);
if (!file_exists($newAbsolutePath)) {
throw new \Exception('Cant copy file! ' . $absolutePath . ' to ' . $newAbsolutePath);
}
$image = new Image();
$image->itemId = $this->owner->primaryKey;
$image->filePath = $pictureSubDir . '/' . $pictureFileName;
$image->modelName = $this->getModule()->getShortClass($this->owner);
$image->urlAlias = $this->getAlias($image);
$image->identifier = $identifier;
$image->name = substr(yii\helpers\Inflector::slug($pictureFileName), 0, -3);
// Get the highest position
// @todo Create function
$owner = $this->owner;
$query = (new yii\db\Query())->select('MAX(`position`)')->from(Image::tableName())->where(['modelName' => yii\helpers\StringHelper::basename($owner::className())]);
$command = $query->createCommand();
$image->position = $command->queryOne(\PDO::FETCH_COLUMN) + 1;
if (!$image->save()) {
return false;
}
// Add the translations
foreach (Yii::$app->params['languages'] as $language => $data) {
$imageLang = new ImageLang();
$imageLang->language = $language;
$image->link('translations', $imageLang);
}
if (count($image->getErrors()) > 0) {
$ar = array_shift($image->getErrors());
unlink($newAbsolutePath);
throw new \Exception(array_shift($ar));
}
$img = $this->owner->getImage();
$this->setMainImage($image);
return $image;
}
示例13: upload
public function upload()
{
if ($this->validate()) {
$image_dir = \Yii::getAlias('@webroot');
$this->_uploaded_url = implode(DIRECTORY_SEPARATOR, ['', self::DIR_UPLOADS, self::DIR_IMAGES, '']);
foreach ($this->_segments as $segment) {
$this->_uploaded_url .= $segment . DIRECTORY_SEPARATOR;
}
BaseFileHelper::createDirectory($image_dir . $this->_uploaded_url, 0775, true);
$this->_uploaded_url .= md5($this->_image_name . time()) . '.' . $this->imageFile->extension;
$this->imageFile->saveAs($image_dir . $this->_uploaded_url);
return true;
} else {
return false;
}
}
示例14: getAllClasses
public static function getAllClasses()
{
$result = [];
foreach (self::getAllAliases() as $alias) {
$path = \Yii::getAlias($alias);
$files = is_dir($path) ? BaseFileHelper::findFiles($path) : [$path];
foreach ($files as $filePath) {
if (!preg_match('/.*\\/[A-Z]\\w+\\.php/', $filePath)) {
continue;
}
$className = str_replace([$path, '.php', '/', '@'], [$alias, '', '\\', ''], $filePath);
$result[] = $className;
}
}
return $result;
}
示例15: actionFileUploadAvatar
public function actionFileUploadAvatar()
{
if (Yii::$app->request->isPost) {
$id = Yii::$app->user->id;
$model = User::findOne($id);
$path = Yii::getAlias("@frontend/web/images/users/");
BaseFileHelper::createDirectory($path);
$model->scenario = 'view';
$file = UploadedFile::getInstance($model, 'imgsource');
$name = $file->baseName . '.' . $file->extension;
$file->saveAs($path . DIRECTORY_SEPARATOR . $name);
$model->imgsource = $name;
$model->save();
return true;
}
return false;
}