Précédent   Forum des professionnels en informatique > PHP > Langage > Fichiers
Fichiers Forum d'entraide sur les fichiers avec PHP. Avant de poster -> FAQ fichiers et Sources fichiers
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/11/2010, 20h51   #1
Invité de passage
 
Inscription : juin 2004
Messages : 16
Détails du profil
Informations forums :
Inscription : juin 2004
Messages : 16
Points : 4
Points : 4
Par défaut Force download *.rtf

Bonjour à tous.
J'ai un petit soucis.
Je génère un .rtf à la volé à grand coup de str_replace.
Jusque là tous va bien.
Le fichier s'enregistre bien et mon textes / tableau se place correctement.
Sauf que, à la fin de mon script, je souhaite forcer le téléchargement.
Code :
1
2
3
4
5
$length = strlen($temp_file); 
//lancement du téléchargement du fichier
header("Content-type: application/rtf");
header("Content-Length: ".$length); 
header("Content-disposition: attachment; filename=\"".$temp_file."\";");
Mais pour une raison inconnu lors de se "force download" cela me met mon index ( la partie html ) dans mon fichier donc le fichier devient corrompu.
Coladin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 21h04   #2
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 815
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 815
Points : 3 440
Points : 3 440
Citation:
Sauf que, à la fin de mon script, je souhaite forcer le téléchargement.
Qu'est-ce qu'il y a sur ta page avant le script collé ci-dessus ?
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 21h13   #3
Invité de passage
 
Inscription : juin 2004
Messages : 16
Détails du profil
Informations forums :
Inscription : juin 2004
Messages : 16
Points : 4
Points : 4
Citation:
$fp = fopen ( $temp_file, 'w' );
fputs($fp,$foutput);
$fileLines=file($temp_file);
$ligne_max = count($fileLines);
fclose($fp);
Ouverture du fichier, ajout de mon "texte", fermeture

edit : redification il me met mon index au complet sans télécharger mon fichier

Code :
1
2
3
{\rtf1\ansi\ansicpg1252\deff0\deflang1036\deflangfe1036\deftab708{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fswiss\fprq2\fcharset0 Calibri;}}
{\colortbl ;\red255\green255\blue255;\red255\green0\blue0;\red0\green0\blue0;}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\li1136\ri260\sa200\sl276\slmult1\qr\f0\fs20{\pict\wmetafile8\picwgoal2265\pichgoal434
Petit morceau de "code" du rtf présent sur le serveur.

Petit morceau de ce que contient le fichier que je télécharge:
Code :
1
2
3
4
5
6
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<script  type="text/javascript" src="./inc/script.js"></script>
		<title></title>
		<link rel="stylesheet" type="text/css" href="./inc/my_css.css" />
Coladin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 21h27   #4
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 815
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 815
Points : 3 440
Points : 3 440
Citation:
$fp = fopen ( $temp_file, 'w' );
fputs($fp,$foutput);
...
Et encore avant ? N'y aurait-il pas ta page HTML ?
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 22h04   #5
Invité de passage
 
Inscription : juin 2004
Messages : 16
Détails du profil
Informations forums :
Inscription : juin 2004
Messages : 16
Points : 4
Points : 4
Non c'est une page à par....hum...
En faite si je suis bête comme c'est un include elle est bien présente ma page html.

Je dois la mettre "à par" ?
Coladin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 22h05   #6
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 815
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 815
Points : 3 440
Points : 3 440
Voui.
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 22h52   #7
Invité de passage
 
Inscription : juin 2004
Messages : 16
Détails du profil
Informations forums :
Inscription : juin 2004
Messages : 16
Points : 4
Points : 4
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php  
      if (isset($_GET['page']))
      { 
        $temp_file=$_GET['page'];
        $length = strlen($temp_file); 
        header("Content-type: application/rtf");
        header("Content-Length: ".$length); 
        header("Content-disposition: attachment; filename=\"".$temp_file."\";");
        copy($temp_file, "./facture/".$temp_file) ;
        unlink($temp_file);          
      }
 
?>
J'ai crée une autre page seul ou je passe le nom en parametre et ... rien
Le fichier fais 0 et vide.
Coladin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2010, 23h13   #8
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 815
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 815
Points : 3 440
Points : 3 440
Nul part tu n'envoies les données au client.
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2010, 00h14   #9
Invité de passage
 
Inscription : juin 2004
Messages : 16
Détails du profil
Informations forums :
Inscription : juin 2004
Messages : 16
Points : 4
Points : 4
La pour le coup je comprend pas
edit:
Done

Code :
1
2
3
4
5
6
7
8
9
10
11
      if (isset($_GET['page']))
      { 
        $temp_file=$_GET['page'];
        $length = strlen($temp_file); 
        header("Content-type: application/rtf");
        //header("Content-Length: ".$length); 
        header("Content-disposition: attachment; filename=\"".basename($temp_file)."\";");
        readfile("$temp_file");
        copy($temp_file, "./facture/".$temp_file) ;
        unlink($temp_file);          
      }
Merci pour ton aide
Coladin est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h31.


 
 
 
 
Partenaires

Hébergement Web