Answer the question
In order to leave comments, you need to log in
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
]);
}
}
<?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;
}
}
move_uploaded_file(): The second argument to copy() function cannot be a directory
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question