Gros bug avec readfile et header en PHP...

Fermé
guillaume_74 Messages postés 111 Date d'inscription samedi 18 octobre 2008 Statut Membre Dernière intervention 29 juillet 2010 - 12 nov. 2009 à 15:48
guillaume_74 Messages postés 111 Date d'inscription samedi 18 octobre 2008 Statut Membre Dernière intervention 29 juillet 2010 - 12 nov. 2009 à 16:02
Bonjour,
Je suis confronté a un gros gros bug....
En gros, j'ai deux lien, pointant sur des fichiers différent, quand je clique dessus, ca me propose de télécharger ce fichier... (je transmets le nom du fichier a une même fonction qui affiche la fenêtre de téléchargement)

Mon problème... c'est que je me suis amusé a alterné entre les deux liens consécutivement... (en cliquant annulé après), a un moment, il me propose de télécharger le script php que j'utilise... ( TRUC DE DINGUE) j'ai continué encore un moment...
Et ca a injecté des caractères en tout genre dans la page web, est-ce qu'il faut libérer quelque chose pour le header?
voici mon bout de code... (le nom de fichier est correcte, j'ai vérifié)
echo "doc: ".$document."<br>";
	$file=fopen('blabla.txt','a+');
	fwrite($file,$document.' \n ');
	fclose($file);
	switch(strrchr(basename($document), ".")) 
	{
		case ".gz": $type = "application/x-gzip"; break;
		case ".tgz": $type = "application/x-gzip"; break;
		case ".zip": $type = "application/zip"; break;
		case ".pdf": $type = "application/pdf"; break;
		case ".png": $type = "image/png"; break;
		case ".gif": $type = "image/gif"; break;
		case ".jpg": $type = "image/jpeg"; break;
		case ".txt": $type = "text/plain"; break;
		case ".htm": $type = "text/html"; break;
		case ".html": $type = "text/html"; break;
		case ".doc": $type = "application/msword"; break;
		default: $type = "application/octet-stream"; break;
	}
	header("Content-disposition:  attachment; filename=$document");
	header("Content-Type: application/force-download");
	header("Content-Transfer-Encoding: $type\n"); // Surtout ne pas enlever le \n
	header("Content-Length: ".filesize(RACINE_PHYS_UPLOAD .'documents/'. $document));
	header("Pragma: no-cache");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
	header("Expires: 0");
	readfile(RACINE_PHYS_UPLOAD .'documents/'. $document); 


je pensais a un problème du cache control...

si quelqu'un pouvais m'aider. Le fwrite, c'était pour m'assurer du nom de fichier a lire...
A voir également:

1 réponse

guillaume_74 Messages postés 111 Date d'inscription samedi 18 octobre 2008 Statut Membre Dernière intervention 29 juillet 2010 22
12 nov. 2009 à 16:02
Surment un problème de cache... mais je ne sais pas de quoi ca vient...
0