S
S
Sergey Beloventsev2016-05-05 17:32:51
Yii
Sergey Beloventsev, 2016-05-05 17:32:51

Why again an error with loading files?

I'm trying to organize the download of the xlsx file. Here is the controller.

public function actionExcelparser(){
            $execelparser= new ParsersExcel();
    
            if ($execelparser->load(Yii::$app->request->post())){
                $execelparser->files = UploadedFile::getInstance($execelparser, 'files');
                $years=date('Y');
                $mounts=date('m');
                $path='files';
                foreach ($execelparser->files as $file) {
                    $files_to = TransliteratorHelper::process($file->name, '', 'en');
                    if ($execelparser->upload($path,$years,$mounts,$files_to)) {
                        $data = \moonland\phpexcel\Excel::import(Yii::getAlias('@frontend/web/').$path.'/'.$years.'/'.$mounts.'/'.$files_to);
                    }
                }
                    return $this->render('excelparser',[
                            'data'=>$data
                    ]);
            }else{
                return $this->render('excelparser', [
                    'model'     => $execelparser
                ]);
            }
        }

here is the model
<?php
    namespace backend\models;
    
    use Yii;
    use yii\base\Model;
    use backend\models\Parsers;
    
    
    class ParsersExcel extends Model{
       public $files;
       //public $excel;
      public function rules()
        {
            return [
                [['files'], 'file','skipOnEmpty' => true, 'extensions' => 'xls, xlsx'],
            ];
        }
        public function upload($path,$years,$mounts,$files_to){
            if ($this->validate()) {
                if (file_exists(Yii::getAlias('@frontend/web/').$path.'/'.$years.'/'.$mounts.'/')) {
                } else {
                    mkdir(Yii::getAlias('@frontend/web/').$path.'/'.$years.'/'.$mounts.'/', 0775, true);
                }
                $this->files->saveAs(Yii::getAlias('@frontend/web/').$path.'/'.$years.'/'.$mounts.'/'.$files_to);
                return true;
            } else {
                return false;
            }
        }

and this is the error it gives me
move_uploaded_file(): The second argument to copy() function cannot be a directory

don't tell me why? And how to organize the download?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Deleted User, 2016-05-05
@Sergalas

You can read about uploading files here .
"The second argument to copy() function cannot be a directory" The second argument must be a file, not a directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question