Ejemplo n.º 1
0
 public function actionCodeImport()
 {
     set_time_limit(0);
     $giftId = Yii::app()->request->getParam('giftId');
     $file = $_FILES;
     if ($file && $giftId) {
         $tmpFile = "upload/" . $_FILES["file"]["name"];
         if (file_exists($tmpFile)) {
             @unlink($_FILES["file"]["name"]);
         } else {
             move_uploaded_file($_FILES["file"]["tmp_name"], $tmpFile);
         }
         $handle = @fopen($tmpFile, "r");
         if ($handle) {
             while (!feof($handle)) {
                 $code = fgets($handle, 4096);
                 //入库
                 $tableName = sprintf(GiftModel::CREATE_CODE_TABLE_NAME, $this->wechatInfo->id);
                 $CodeModel = new GiftCodeModel($tableName);
                 $CodeModel->giftId = $giftId;
                 $CodeModel->code = trim($code);
                 $CodeModel->save();
             }
             fclose($handle);
         }
         @unlink($tmpFile);
         $msg = "导入成功!";
     } else {
         $msg = '提交错误';
     }
     echo $msg;
 }