<?php
$aARQ = @$aSessao['CAR_ARQ'];
OB_CLEAN();
If ( EMPTY($sAcao) ) {
   If ( STRLEN(@$aARQ['TYPE'])>0 ) {
      HEADER("Content-Type: ".$aARQ['TYPE']);
      HEADER("Content-Length: ".$aARQ['SIZE']);
      //HEADER("Cache-Control: no-cache");
	  HEADER("Cache-Control: no-store, no-cache, must-revalidate"); 
      HEADER("Cache-Control: post-check=0, pre-check=0", false); 
      HEADER("Pragma: no-cache"); 
	  HEADER("Content-Disposition: attachment; filename=".$aARQ['NAME']);
      ECHO $aARQ['CONT'];
   }
} ElseIf ($sAcao == "DATA_BASE") {
      $Row_CadArq = MYSQL_QUERY( "SELECT * FROM cad_arquivos WHERE ARQ_CODIGOI=".@$_REQUEST['Arq_CodigoI'].";" ) Or Die(MYSQL_ERROR());
      If ( $Row_CadArq = MYSQL_FETCH_OBJECT($Row_CadArq) ) {
 	     If ( STRLEN($Row_CadArq->ARQ_TP_MIME)>0 ) {
            HEADER("Content-Type: ".$Row_CadArq->ARQ_TP_MIME);
            HEADER("Content-Length: ".$Row_CadArq->ARQ_TAMANHO);
	        HEADER("Cache-Control: no-store, no-cache, must-revalidate"); 
            HEADER("Cache-Control: post-check=0, pre-check=0", false); 
            HEADER("Pragma: no-cache"); 
	        HEADER("Content-Disposition: attachment; filename=".$Row_CadArq->ARQ_NOMEARQ);
            ECHO $Row_CadArq->ARQ_BINARIO;
		 }
	  }
} ElseIf ($sAcao == "UPLOAD") {
   If ( STRLEN(@$_FILES['Entrada_Arq']['tmp_name'])>3 ) {
      $aEntArq = $_FILES['Entrada_Arq'];
      $nArq_Tamanh = FILESIZE($aEntArq['tmp_name']);
	  If ( $nArq_Tamanh<100000 ) {
         $nArq_Handle = FOPEN($aEntArq['tmp_name'],"rb");
	     $sArq_Conteu = FREAD($nArq_Handle, $nArq_Tamanh);
	     FCLOSE($nArq_Handle);
	 	 $aARQ['TYPE'] = $aEntArq['type'];
		 $aARQ['SIZE'] = $nArq_Tamanh;
		 $aARQ['NAME'] = $aEntArq['name'];
		 $aARQ['CONT'] = $sArq_Conteu;
	     $aARQ['ALTERADO'] = 1;
		 //
		 $sRet_Javs .= $aARQ['JAVA_UPLOAD'];
	  } Else {
	     $aARQ['TYPE'] = '';
	     $aARQ['SIZE'] = 0;
	     $aARQ['NAME'] = '';
	     $aARQ['CONT'] = '';
	     $aARQ['ALTERADO'] = 1;
		 $sRet_Javs .= $aARQ['JAVA_UPLOAD'];
	  }
      $aSessao['CAR_ARQ'] = $aARQ;
   }
} ElseIf ($sAcao == "CLEAR") {
   $aARQ['TYPE'] = '';
   $aARQ['SIZE'] = 0;
   $aARQ['NAME'] = '';
   $aARQ['CONT'] = '';
   $aARQ['ALTERADO'] = 1;
   $aSessao['CAR_ARQ'] = $aARQ;
   $sRet_Javs .= $aARQ['JAVA_UPLOAD'];
}
?>