Bogue rubrique téléchargement + Solution
Fichier qui ne se télécharge pas ?
Support Général
Fantole Membre non connecté
Booster Bazooka
-
Booster Bazooka
- Voir le profil du membre Fantole
- Inscrit le : 28/05/2008

Sur mon site quand j'ajoute un téléchargement je procède de cette façon.
Code TEXT :
../download/NOM_DU_FICHIER.EXTENSION
Bon aucun problème le fichier se télécharge sans problème.
Par contre les autres Admins de mon site ont accès à un FTP sous un sous nom de domaine.
Donc le chemin relatif ne peux fonctionner.
Donc je faisais
Code TEXT :
http://SOUS_NOM_DE_DOMAINE.NOM_DE_DOMAINE.com/download/NOM_DU_FICHIER.EXTENSION
Et quand on clique pour télécharger on tombe sur une page blanche avec dans l'url les paramètres ID de catégorie, etc...
J'ai donc modifié
Code PHP :
<?php /*################################################## * count.php * ------------------- * begin : July 27, 2005 * copyright : (C) 2005 Viarre Régis * email : crowkait@phpboost.com * * ################################################### * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ###################################################*/ include_once('../includes/begin.php'); $idurl = !empty($_GET['id']) ? numeric($_GET['id']) : 0; if( !empty($idurl) ) $sql->query_inject("UPDATE ".PREFIX."download SET compt = compt + 1 WHERE id = '" . $idurl . "'", __LINE__, __FILE__); //MAJ du compteur. $file_path = $sql->query("SELECT url FROM ".PREFIX."download WHERE id = '" . $idurl . "'", __LINE__, __FILE__); //Redirection vers le fichier demandé! header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); $filesize = @filesize($file_path); header("Content-Length: " . $filesize); header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . substr(strrchr($file_path, '/'), 1) . '"'); if( $filesize !== false ) header("Content-Length: " . $filesize); header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . substr(strrchr($file_path, '/'), 1) . '"'); if( @readfile($file_path) === false ) { header('location:' . $file_path, true); exit; } ?>
Par
Code PHP :
<?php /*################################################## * count.php * ------------------- * begin : July 27, 2005 * copyright : (C) 2005 Viarre Régis * email : crowkait@phpboost.com * * ################################################### * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ###################################################*/ include_once('../includes/begin.php'); $idurl = !empty($_GET['id']) ? numeric($_GET['id']) : 0; if( !empty($idurl) ) $sql->query_inject("UPDATE ".PREFIX."download SET compt = compt + 1 WHERE id = '" . $idurl . "'", __LINE__, __FILE__); //MAJ du compteur. $file_path = $sql->query("SELECT url FROM ".PREFIX."download WHERE id = '" . $idurl . "'", __LINE__, __FILE__); //Redirection vers le fichier demandé! header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); $filesize = @filesize($file_path); //header("Content-Length: " . $filesize); //header("Content-Type: application/octet-stream"); //header('Content-Disposition: attachment; filename="' . substr(strrchr($file_path, '/'), 1) . '"'); if (preg_match('@^(?:http://)?([^/]+)@i', $file_path)) { header("Content-Length: " . $filesize); header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . substr(strrchr($file_path, '/'), 1) . '"'); header('location:' . $file_path, true); exit; } else { if( $filesize !== false ) header("Content-Length: " . $filesize); header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . substr(strrchr($file_path, '/'), 1) . '"'); if( @readfile($file_path) === false ) { header('location:' . $file_path, true); exit; } } ?>
Je tenais à partager
ben.popeye Membre non connecté
-
Modérateur
- Voir le profil du membre ben.popeye
- Inscrit le : 04/08/2005
- Site internet
- Groupes :
-
Equipe Historique
Un problème, une question ? Cherchez dans la FAQ ou la documentation. Si vous ne trouvez pas la réponse, demandez du support sur le forum.
Bjarne Stroustrup, inventeur du C++ :"There are two ways to write error-free programs; only the third works."
Fantole Membre non connecté
Booster Bazooka
-
Booster Bazooka
- Voir le profil du membre Fantole
- Inscrit le : 28/05/2008
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie