Forcer download

Profil bloqué - 25 août 2010 à 20:15
cs_Dje33 Messages postés 25 Date d'inscription mardi 29 juin 2010 Statut Membre Dernière intervention 19 octobre 2010 - 5 sept. 2010 à 23:44
Bonjour , bien que je trouve plein de script pour forcer le téléchargement d'un fichier , je n'arrive à en faire fonctionner aucun ...

Quelqu'un pourrait il m apporter son aide ??

Merci

8 réponses

cs_47 Messages postés 197 Date d'inscription mardi 20 janvier 2004 Statut Membre Dernière intervention 20 février 2013 1
25 août 2010 à 22:50
Bonsoir,

Quel code utilises-tu?

De tête, ça devrait ressembler à ceci:
<?php

$sFileName = 'monfichier.txt';
$sFileNameWithPath = $sPath . '/' . $sFileName;
header("Content-disposition: attachment; filename=$sFileName");
header("Content-Type: application/force-download");
// à changer suivant le type de fichier
header("Content-Transfer-Encoding: text/plain\n");
header("Content-Length: " . filesize($sFileNameWithPath));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($sFileNameWithPath); 



bonne soirée
0
Profil bloqué
25 août 2010 à 22:57
Voilà , j'ai inséré le code suivant , il m'enregistre l'image mais impossible de l'ouvrir ....

<?php

$sFileName = 'image1.jpg';
$sFileNameWithPath = $sPath . '/' . $sFileName;
header("Content-disposition: attachment; filename=$sFileName");
header("Content-Type: application/force-download");
// à changer suivant le type de fichier
header("Content-Transfer-Encoding: text/plain\n");
header("Content-Length: " . filesize($sFileNameWithPath));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($sFileNameWithPath); 

?>
0
cs_47 Messages postés 197 Date d'inscription mardi 20 janvier 2004 Statut Membre Dernière intervention 20 février 2013 1
25 août 2010 à 23:21
Re,

pour une image au format jpg, remplace :

header("Content-Transfer-Encoding: text/plain\n");

par

header("Content-Transfer-Encoding: image/jpeg\n");
0
Profil bloqué
25 août 2010 à 23:55
j'ai essayer .... ça ne marche toujours pas ....
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
26 août 2010 à 11:04
Bonjour,

pour forcer un download je fais une redirection vers le fichier.zip
<META HTTP-EQUIV="Refresh"

      CONTENT="0; URL=mytweetter.zip"/> 



a+
google est mon ami quand tu cherches quelque chose demande lui clairement
0
cs_47 Messages postés 197 Date d'inscription mardi 20 janvier 2004 Statut Membre Dernière intervention 20 février 2013 1
27 août 2010 à 09:20
Re,

on va prendre un exemple

voici l'arborescence du projet:
download.php
images/image1.jpg

(l'image est dans un répertoire au dessus du script de download)

donc dans le script, il te faudra
$sFileName = 'images/image1.jpg';
et
$sPath = dirname(__FILE__);

bonne journée
0
Profil bloqué
27 août 2010 à 13:20
Toujours pas de réussite ...

Voici mon code :

$sFileName = 'image/image1.jpg';
$sPath = dirname(__FILE__);
header("Content-disposition: attachment; filename=$sFileName");
header("Content-Type: application/force-download");
// à changer suivant le type de fichier
header("Content-Transfer-Encoding: image/jpeg\n");
header("Content-Length: " . filesize($sFileNameWithPath));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($sFileNameWithPath);
0
cs_Dje33 Messages postés 25 Date d'inscription mardi 29 juin 2010 Statut Membre Dernière intervention 19 octobre 2010
5 sept. 2010 à 23:44
Salut,

et avec ceci :

<?php
$_GET['doc'];
$fichier = $_GET['doc'];
$chemin = 'fichier/' . $fichier;
if (file_exists($chemin))
{
header('Content-disposition: attachment; filename="' . $fichier . '"');
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '. filesize($chemin));
header('Pragma: no-cache');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
readfile($chemin);
}
else
{
$erreurFichier = 'le fichier "' . $fichier . '" n\'existe pas. Veuillez-nous excusez pour le désagrément.';
}
?>
0
Rejoignez-nous