fix: throw validation error for filename
This commit is contained in:
parent
976e463f5c
commit
572dae98ab
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace app\models;
|
||||
|
||||
use Anper\Iuliia\Iuliia;
|
||||
use Yii;
|
||||
use yii\helpers\FileHelper;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\UploadedFile;
|
||||
|
||||
/**
|
||||
|
@ -37,9 +39,13 @@ class Image extends \yii\db\ActiveRecord
|
|||
|
||||
copy($file->tempName, env('UPLOADS_PATH') . '/' . $hash);
|
||||
|
||||
if (!preg_match('/^[a-z0-9-_]+(|\.[\w\d]+)$/i', Iuliia::translate($file->name, Iuliia::WIKIPEDIA))) {
|
||||
throw new BadRequestHttpException('Filename must be a-Z0-9_-!');
|
||||
}
|
||||
|
||||
$new = new Image([
|
||||
'sha256' => $hash,
|
||||
'original_name' => $file->name,
|
||||
'original_name' => Iuliia::translate($file->name, Iuliia::WIKIPEDIA),
|
||||
'mime' => FileHelper::getMimeType($file->tempName)
|
||||
]);
|
||||
$new->save(true);
|
||||
|
@ -54,7 +60,7 @@ class Image extends \yii\db\ActiveRecord
|
|||
{
|
||||
return [
|
||||
[['sha256', 'original_name'], 'required'],
|
||||
[['sha256', 'original_name'], 'string', 'max' => 255],
|
||||
[['original_name'], 'match', '/^[a-z0-9-_]+(|\.[\w\d]+)$/i'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue