R
R
Ruslan Dzh2019-03-13 09:19:13
Yii
Ruslan Dzh, 2019-03-13 09:19:13

How to add a check for matching a specific file name when importing?

I use yii2 basic and PHPExcel_IOFactory
There is a form with some file import into the database.
It is necessary that when importing a file, the file meets certain criteria:
1. The file name begins with the imp_ prefix
2. The file extension is xml, xls, xlsx
How to check the extension - figured it out, but I just can't figure out how to check the file name?
Source:

public function actionImport()
{
  $modelImport = new \yii\base\DynamicModel(['fileImport' => 'Импорт файла']);
  $modelImport->addRule(['fileImport'],'required');
  $modelImport->addRule(['fileImport'],'file',['extensions'=>'xml,ods,xls,xlsx'],['maxSize'=>1024*1024]);

  if(Yii::$app->request->post()) {
    $this->import($modelImport);
  }

  return $this->render('import',[
    'modelImport' => $modelImport,
  ]);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2019-03-13
@rdzh

https://www.yiiframework.com/doc/api/2.0/yii-web-u... Have you
completely forgotten how to read the docks? or can't we? This task not only does not apply to PHPExcel_IOFactory, but to yii2 as a matter of fact. Fundamentals of uploading files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question