<?php
//共通
require_once '../base/common.php';
require_once '../util/fileUtil.php';
$logger = new logger(basename(__FILE__));
$logger->info("===start===");

$response["status"] = "NG";

global $stringUtil;

$request_body = file_get_contents('php://input');
$logger->info("@===requestBody==",$request_body);
$data = json_decode($request_body, true);

try {
  $logger->info("@===info==",   $data);
  $filename = $GLOBALS["UPLOAD_DIR"] . "/" . $data["fileName"];
  $logger->info("@===header==", $filename);

  if(!file_exists($filename)) {
     throw new Exception('??????????');
  }

  $data = file_get_contents($filename);
  $fileUtil = new fileUtil();
  $data1 = $fileUtil->remove_utf8_bom($data);

  // CSV?HTTP???
  header("Content-Type: application/octet-stream;");
  header('Content-Transfer-Encoding: binary');

  echo $data1;

} catch(userException $ue) {
  $retData["code"]  = $ue->getErrorCode();
  $retData["msg"]   = $ue->getErrorMessage();

  $response["status"] = "NG";
  $response["data"]   = $retData;

  $dbutil->rollback();
} catch(Exception $e) {
  $response["status"] = "NG";
  $response["data"]   = $e->getMessage();
}

$logger->info("=== end ===", $response);

?>
