Example #1
0
	function download() {

		//ajaxリクエスト以外
		if( !$this->RequestHandler->isAjax() ) {
			$this->set("result" , array("result" => "not ajax"));
			return;
		}

		//パラメータ解析
		$u_userid=$this->params['form']['u'];
		$u_id=$this->params['form']['id'];
		$u_dtype=$this->params['form']['d'];
		if ( $u_userid == "" or $u_id == "" or $u_dtype == "" ){
			$this->set("result" , array("result" => "parameter error"));
			return;
		}

		//ファイルの中身を返す
		if ( $u_dtype == "csv" ){

			//処理中チェック
			$pid_file=DIR_RESULT."/${u_userid}/${u_id}.pid";
			if ( file_exists($pid_file) ){
				$this->set("result" , array("result" => "ok", "id" => "$u_id", "datas"=>"", "dtype" => $u_dtype));
				return;
			}

			//zipファイルの場合
			$read_file=DIR_RESULT."/${u_userid}/${u_id}_000.zip";
			if ( file_exists($read_file) ){
				$this->log("$read_file",LOG_DEBUG);
				$datas=CommonComponent::ZipFileRead($read_file,$u_dtype);
				$this->set("result" , array("result" => "ok", "datas" => $datas, "dtype" => $u_dtype));
				return;
			}

			//gzipファイルの場合
			$read_file=DIR_RESULT."/${u_userid}/${u_id}_000.csv.gz";
			if ( file_exists($read_file) ){
				$this->log("$read_file",LOG_DEBUG);
				$datas=CommonComponent::GZipFileRead($read_file,$u_dtype);
				$this->set("result" , array("result" => "ok", "datas" => $datas, "dtype" => $u_dtype));
				return;
			}

		}else{
			$read_file=DIR_RESULT."/${u_userid}/${u_id}.${u_dtype}";
			$this->log("$read_file",LOG_DEBUG);
			if ( file_exists($read_file) ){
				$datas=CommonComponent::FileRead($read_file,$u_dtype);
				$this->set("result" , array("result" => "ok", "datas" => $datas, "dtype" => $u_dtype));
				return;
			}
		}

		$this->set("result" , array("result" => "no file", "id" => "$u_id", "datas"=>"", "dtype" => $u_dtype));
	}