Generate RTF with PHP

0

I have the following code, which works perfectly, just that I need that when executing, this gives me the option of where to save the generated document. I have been reviewing the documentation and some examples on the Internet, but I have not been successful.

<?php 

function leef($fichero){
	$texto = file($fichero);
	$tamleef=sizeof($texto);
	for($n=0;$n<$tamleef;$n++)
	{ $todo = $todo.$texto[$n];}
	return $todo;
}

function rtf($sql, $plantilla, $fsalida, $matequivalencias){
	$pre=time();
	$fsalida="C:\Users\usertic\Desktop/".$fsalida;
	require('../conexion.php');

	$txtplantilla=leef($plantilla);
	
	$matriz=explode("sectd", $txtplantilla);
	$cabecera=$matriz[0]."sectd";
	$inicio=strlen($cabecera);
	$final=strrpos($txtplantilla, "}");
	$largo=$final-$inicio;
	$cuerpo=substr($txtplantilla,$inicio, $largo);

	$punt=fopen($fsalida, "w");
	fputs($punt,$cabecera);
	$result = $mysqli->query($sql);
	while ($row=$result->fetch_array()){

		$despues=$cuerpo;
		foreach ($matequivalencias as $dato) {
			$datosql = $row[$dato[1]];
			$datosql=stripslashes($datosql);
			$datortf=$dato[0];
			$despues=str_replace($datortf, $datosql, $despues);
		}

	fputs($punt, $despues);
	$saltopg="\par \page \par";
	fputs($punt, $saltopg);

	}

fputs($punt, "}");
fclose($punt);
return $fsalida;
}

$predio=$_POST['predio'];

$plantilla = 'Notificaciones_proyecto.rtf';
$sql = "SELECT TPRO_NOMBR,TOBR_TPOOB,TOBR_NOMBR,TROZ_DESCR,TROZ_MUNIC,TROZ_ESTAD,TROZ_DOMIC,TROZ_TELEF,TPRE_NOMPR,TPRE_UBICA,TPER_NOMBR
		FROM tpredio AS tpre
		INNER JOIN tpred_prop AS tpp ON tpre.TPRE_IDPRE=tpp.TPRP_IDPRE
		INNER JOIN tpropietario AS tpro ON tpp.TPRP_IDPRO=tpro.TPRO_IDPRO
		INNER JOIN tobra AS tob ON tob.TOBR_IDOBR=tpre.TPRE_IDOBR
		INNER JOIN rozona AS roz ON roz.TROZ_IDROZ=tob.TOBR_RZONA
		INNER JOIN tpersonal as tper ON roz.TROZ_IDROZ=tper.TPER_IDROZ
		WHERE tpre.TPRE_IDPRE='$predio'
        GROUP BY tpre.TPRE_IDPRE";

$equivalencias[0][0]="#*NombrePr*#";
$equivalencias[0][1]="TPRO_NOMBR";
$equivalencias[1][0]="#*tipoO*#";
$equivalencias[1][1]="TOBR_TPOOB";
$equivalencias[2][0]="#*NombreO*#";
$equivalencias[2][1]="TOBR_NOMBR";
$equivalencias[3][0]="#*DescripcionR*#";
$equivalencias[3][1]="TROZ_DESCR";
$equivalencias[4][0]="#*DomicilioR*#";
$equivalencias[4][1]="TROZ_DOMIC";
$equivalencias[5][0]="#*MunicipioR*#";
$equivalencias[5][1]="TROZ_MUNIC";
$equivalencias[6][0]="#*EdoR*#";
$equivalencias[6][1]="TROZ_ESTAD";
$equivalencias[7][0]="#*TelR*#";
$equivalencias[7][1]="TROZ_TELEF";
$equivalencias[8][0]="#*NombreP*#";
$equivalencias[8][1]="TPRE_NOMPR";
$equivalencias[9][0]="#*ubica*#";
$equivalencias[9][1]="TPRE_UBICA";
$equivalencias[10][0]="#*Nombre*#";
$equivalencias[10][1]="TPER_NOMBR";








$salida =rtf($sql,$plantilla, "Notificaciones de proyecto y autorización de estudios preliminares.rtf",$equivalencias);
echo $salida; 
?>
    
asked by Erik Raúl González Páez 12.11.2018 в 18:14
source

0 answers