Ver Mensaje Individual
  #7 (permalink)  
Antiguo 30/09/2013, 01:53
asantosarrate
 
Fecha de Ingreso: septiembre-2013
Mensajes: 8
Antigüedad: 10 años, 7 meses
Puntos: 0
Respuesta: Plantillas para Word en PHP

Ahora me pasa algo más extraño todavía (os voy a poner todo el código fuente al completo para que no haya dudas):

en la función "descargar" abajo no se cumple "if (is_file($ruta))"; es false, por lo tanto no ejecuta la descarga; de todas formas si fuerzo la descarga comentando ese IF, el fichero que me descarga contiene sólo el HTML que voy componiendo a lo largo de este fichero: "Etiquetas generadas", etc.

Algo está fallando ahí y no sé el qué es, pero ya os digo que los ficheros los genera correctamente, es decir, si no incluyo lo de la descarga y me los descargo yo mismo vía ftp los ficheros están perfectos; allá va el código (gracias):


<?php
include("./includes/seguridad.php");
include("./includes/funciones.php");

function csv_encode_conv($var, $enc='Windows-1252') {
$var = htmlentities($var, ENT_QUOTES, 'utf-8');
$var = html_entity_decode($var, ENT_QUOTES , $enc);
return $var;
}


$pedido_find=$_SESSION["pedido"];
$sql = "SELECT * FROM basereparaciones.t_cabecera, basereparaciones.t_detalle WHERE t_cabecera.pedido = t_detalle.pedido
and t_detalle.pedido = '".$pedido_find."'";

$res = mysqli_query($link,$sql);
?>
<body bgcolor = "#DDDDDD" >
<center><h1 style='font-family:Calibri; font-size:28px; font-weight:bold; color:green;'>Etiquetas generadas:<br></h2>

<?
while ($row = mysqli_fetch_array($res)){
$num_documento_find = $row["num_documento"];
$pedido_find = $row["pedido"];
$partida_find = $row["partida"];

$archivo = file_get_contents('plantilla_etiquetas.rtf');
$archivo = str_replace('tag_num_documento',csv_encode_conv($n um_documento_find),$archivo);
$archivo = str_replace('tag_pedido',csv_encode_conv($pedido_f ind),$archivo);
$archivo = str_replace('tag_partida',csv_encode_conv($partida _find),$archivo);


file_put_contents('./etiquetas/et_doc_'.$num_documento_find.'_part_'.$partida_fin d.'.rtf',$archivo);

echo '<H3 style="font-family:Calibri; font-size:20px; font-weight:bold; color:green;">et_doc_'.$num_documento_find.'_part_ '.$partida_find.'.rtf</H2>';

descargar('et_doc'.$num_documento_find.'_part_'.$p artida_find.'.rtf');
}


function descargar($archivo){

$ruta = './etiquetas/'.$archivo;

if (is_file($ruta))
{
//header ("Content-Type: application/octet-stream");
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename='.$archivo);
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($ruta));

readfile($ruta);
}
//else
//exit();
}

?>
<table border = 0><tr>
<td><input type="button" name="nvolver" value=' Volver ' style = 'font-size:10px; font-family:Verdana; font-weight:bold; color:white; background:#638cb5; border:0px; width:80px; height:19px;cursor:pointer;' onclick="redirec();" onmouseover='style.color = "yellow";' onmouseout='style.color = "#FFFFFF";'></td>

<td><input type="button" name="salir" value=' Salir ' style = 'font-size:10px; font-family:Verdana; font-weight:bold; color:white; background:#638cb5; border:0px; width:80px; height:19px;cursor:pointer;' onclick="salir2();" onmouseover='style.color = "yellow";' onmouseout='style.color = "#FFFFFF";'></td>
</tr></table>
</center>

<script language=javascript>


function redirec(){
location.href="http://www...."
}
function salir2(){
location.href="http://www...."
}

</script>
</body>