upload()) { return $this->getCsv($path); } } /** * upload() * 上传 * ---------------- * @return Boolean * @author coldwind */ protected function upload() { $name = date("Ymd", time()). '_'. Yii::$app->security->generateRandomString(5). '.'. 'csv'; $path = Yii::$app->getBasePath() . "/web/upload". DIRECTORY_SEPARATOR. 'csv'. DIRECTORY_SEPARATOR. $name; if ($this->file->saveAs($path)) { return $path; } return false; } /** * upload() * 上传 * ---------------- * @return object * @author coldwind */ protected function getCsv($path) { $handle = fopen($path, 'r'); $uid = []; $key = null; while (! feof($handle)) { $file = fgetcsv($handle,0, ','); if (is_array($file)) { if (empty($key)) { $key = array_search('uid', $file); } $uid[] = $file[$key]; } } unset($uid[0]); fclose($handle); return $uid; } }