我正在用代码接收编写功能测试,需要上传一个excel文件,然后读取数据以更新我的数据库。但是,在测试文件上传时,它返回成功,但是当从该文件读取数据时,出现一个错误,提示找不到文件。
我的excel文件在_data文件夹下。这是我的上传测试
public function uploadTest(FunctionalTester $I)
{
$I->amOnPage('/import');
$I->wantTo('test file upload');
$I->attachFile('#uploadform-excelfile', 'import.xlsx');
$I->click('#import button[type=submit]');
}
这是我的控制者;
$uploadModel->excelFile = UploadedFile::getInstance($uploadModel, 'excelFile');
if (!$uploadModel->excelFile) {
Yii::$app->getSession()->setFlash('errorMessage', 'Please choose a file to upload');
return $this->redirect("import");
}
if (!$uploadModel->upload("import_" . date("ymd") . "_" . time())) {
Yii::$app->getSession()->setFlash('errorMessage', 'Something went wrong during file upload');
return $this->redirect("import");
}
$data = \moonland\phpexcel\Excel::widget([
'mode' => 'import',
'fileName' => $uploadModel->filePath,
'setFirstRecordAsKeys' => true, // if you want to set the keys of record column with first record, if it not set, the header with use the alphabet column on excel.
'setIndexSheetByName' => false, // set this if your excel data with multiple worksheet, the index of array will be set with the sheet name. If this not set, the index will use numeric.
]);
这是收到的错误;
[PHPExcel_Reader_Exception] Could not open
../uploads/import_180703_1530601552.xlsx for reading! File does not exist.