本文整理汇总了PHP中app\models\File::generateName方法的典型用法代码示例。如果您正苦于以下问题:PHP File::generateName方法的具体用法?PHP File::generateName怎么用?PHP File::generateName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\File
的用法示例。
在下文中一共展示了File::generateName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGenerateName
public function testGenerateName()
{
$file = new File();
$file->generateName('png');
$pathinfo = pathinfo($file->name);
expect($pathinfo)->hasKey('basename');
expect($pathinfo)->hasKey('filename');
expect($pathinfo)->hasKey('extension');
expect($pathinfo['extension'])->equals('png');
}
示例2: function
return $file;
}, 'updateFile' => function ($file) {
if (is_array($this->galleryTitles)) {
$file->title = ArrayHelper::getValue($this->galleryTitles, $file->id, $file->title);
}
return $file;
}, 'extraFields' => function ($file, $fields) {
$position = 0;
if (is_array($this->galleryTitles)) {
$position = array_search($file->id, array_keys($this->galleryTitles));
$position++;
}
return ['type' => 2, 'position' => $position];
}, 'relationQuery' => function ($query) {
return $query->andWhere(['type' => 2]);
}, 'rules' => ['imageSize' => ['minWidth' => 300, 'minHeight' => 300], 'mimeTypes' => ['image/png', 'image/jpg', 'image/jpeg'], 'extensions' => ['jpg', 'jpeg', 'png'], 'maxSize' => 1024 * 1024 * 1, 'maxFiles' => 10, 'tooBig' => Yii::t('app.validators', 'File size must not exceed') . ' 1Mb'], 'preset' => ['80x80' => function ($realPath, $publicPath, $thumbPath) {
Image::make($realPath . $publicPath)->fit(80, 80)->save($realPath . $thumbPath, 100);
}]], 'text' => ['storage' => 'localFs', 'baseUrl' => '@web/uploads', 'type' => 'image', 'relation' => 'files', 'templatePath' => function ($file) {
$date = new \DateTime(is_object($file->date_create) ? null : $file->date_create);
return '/' . $date->format('Ym') . '/' . $file->id . '/' . $file->name;
}, 'createFile' => function ($path, $name) {
$file = new File();
$file->title = $name;
$file->generateName(pathinfo($name, PATHINFO_EXTENSION));
$file->save();
return $file;
}, 'extraFields' => function () {
return ['type' => 3];
}, 'relationQuery' => function ($query) {
return $query->andWhere(['type' => 3]);
}, 'rules' => ['mimeTypes' => ['image/png', 'image/jpg', 'image/jpeg'], 'extensions' => ['jpg', 'jpeg', 'png'], 'maxSize' => 1024 * 1024 * 1, 'tooBig' => Yii::t('app.validators', 'File size must not exceed') . ' 1Mb']]]];