vegetalain
Messages postés747Date d'inscriptionmardi 25 mars 2003StatutMembreDernière intervention11 août 2022
-
25 avril 2010 à 21:54
vegetalain
Messages postés747Date d'inscriptionmardi 25 mars 2003StatutMembreDernière intervention11 août 2022
-
27 avril 2010 à 16:57
Salut tout le monde... hm, voilà, j'aurais aimé faire un listing des fichiers se trouvant dans un dossier, le tout dans un tableau avec un petit png (par exemple : [°.°]) à côté, et un lien de téléchargement genre :
devil_may_cry
Messages postés194Date d'inscriptiondimanche 18 mars 2007StatutMembreDernière intervention11 juillet 2015 27 avril 2010 à 05:21
aller voila pour toi
//listing du repertoire
$dir = "chemin vers le reprtoire";
$tabfile = array();//notre tableau qui vas contenir les fichier et les parametre que tu a defint ci-dessu c'est a dire la taille le nom de l'image et le lien de telechargement
//on verifie si le repertoire est valide
if (is_dir($dir)) {
// on ouvre le repertoire
$handle = opendir($dir);
$i =0; //compteur
//on le parcours
while ($file = readdir($handle)) {
//le '.' t le '..' sont les repertoire courant et sous dossier onc on evite des comptabiliser
if ($file !='.' && $file !='..') {
//on construit le tableau
//j'ai choisit que ca soit associatif pour te facilter la tache a l'affichage
//ceci est la page qui vas lancer le telechargement tu y met
$file = $_GET['file'];
$filename = basename($file);
echo $filename;
$size = filesize($file);
header("Content-Type: image/jpeg");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename="$filename"");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("location:$file");
et par miracle quand tu clique sur le lien le telechargement ce lance
vegetalain
Messages postés747Date d'inscriptionmardi 25 mars 2003StatutMembreDernière intervention11 août 2022 27 avril 2010 à 09:57
Salut et merci pur le code.
Hm... je l'ai testé et après quelques erreurs qui s'affichaient ligne 24 (un slash) et ligne 43 (des points virgules et un crochet), il m'affiche ça :
chipie.jpegfichierbiduleqsdmflkj.txt981765
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 51
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 52
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 53
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 54
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 55
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 56
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 57
Warning: Cannot modify header information - headers already sent by (output started at /mnt/113/sdb/1/f/vegetalain/Beta/index.php:43) in /mnt/113/sdb/1/f/vegetalain/Beta/index.php on line 58
alors les fichiers sont bien listés (chipie.jpegfichierbiduleqsdmflkj.txt981765), mais sans espace et en une ligne, et après je fais AAAAAAAAAAAAARGH 8D
ça correspond à ça dans ce que tu m'as donné :
header("Content-Type: image/jpeg");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename="$filename"");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("location:$file");
devil_may_cry
Messages postés194Date d'inscriptiondimanche 18 mars 2007StatutMembreDernière intervention11 juillet 2015 27 avril 2010 à 15:47
non c'est pas un bug il ne doit pas y avoir un affichage avant d'appeler les fonction header de php c'est a dire tu ne peut pas faire
echo "test";
header("location:..."); etc...
ou bien placer du code html avant de les appeler je vais te proposer 2 solution
la premiere c'est de mettre le code dans une autre page dont le lien du download pointera
<?
//... au affichage au prealable
header("Content-Type: image/jpeg");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename="$filename"");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("location:$file");
et pour la deuxieme solution c'est utiliser les fonction ob_start et ob_end_flush() si tu opte pour cette methode je poura te poster le code et les explication necessaire
?>
devil_may_cry
Messages postés194Date d'inscriptiondimanche 18 mars 2007StatutMembreDernière intervention11 juillet 2015 27 avril 2010 à 16:53
regarde bien l'url je ne vois pas que file pointe sur le chemein absolue vers le fichier tu a file = trucs/chipie.jpeg verifie bien l'url
sinon tu peut remplacer
header("location:$file"); par readfile($file);