[RÉSOLU] Script forcer téléchargement: marche pas

Petit nouveau ! | 1 Messages

24 juin 2010, 11:59

Bonjour,

J'ai testé un script pour forcer le téléchargement d'un fichier uploadé.

http://php.developpez.com/faq/?page=fic ... cedownload

Cela dit il ne fonctionne pas :(

Ce que j'ai fait:

-J'ai placé mon fichier dans un répertoire de mon site :
http://monsite.com/antipubs/Pubs.xml

- J'ai crée le script (en .php) pour forcer un téléchargement, placé dans le même répertoire que le fichier:

Code : Tout sélectionner

<?php $full_path = '/antipubs/Pubs.xml'; // chemin système (local) vers le fichier $file_name = basename($full_path); ini_set('zlib.output_compression', 0); $date = gmdate(DATE_RFC1123); header('Pragma: public'); header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Content-Tranfer-Encoding: none'); header('Content-Length: '.filesize($full_path)); header('Content-MD5: '.base64_encode(md5_file($full_path))); header('Content-Type: application/octetstream; name="'.$file_name.'"'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); header('Date: '.$date); header('Expires: '.gmdate(DATE_RFC1123, time()+1)); header('Last-Modified: '.gmdate(DATE_RFC1123, filemtime($full_path))); readfile($full_path); exit; ?>


-> En allant sur http://monsite.com/antipubs/Pubs.xml, mon navigateur lis ce fichier, au lieu de me proposer de le télécharger...

Comment faire svp ?
Merci de vos aides
Modifié en dernier par Snake38 le 25 juin 2010, 22:25, modifié 1 fois.

ViPHP
ViPHP | 5462 Messages

24 juin 2010, 13:04

met juste ca en header
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'.$file_name.'"');

Snake38_invite
Invité n'ayant pas de compte PHPfrance

24 juin 2010, 17:07

Ne marche pas non plus..

ViPHP
ViPHP | 5462 Messages

24 juin 2010, 17:09

c'est ton fichier php qu'il faut ouvrir pas le fichier xml :wink:
mais tu pourrais faire du rewrting pour pointer direct sur un lien .xml

Snake38_invite
Invité n'ayant pas de compte PHPfrance

25 juin 2010, 21:40

c'est ton fichier php qu'il faut ouvrir pas le fichier xml :wink:
mais tu pourrais faire du rewrting pour pointer direct sur un lien .xml
Arf, oui ça marche maintenant !

Quel genre de rewriting ?

Snake38_invite
Invité n'ayant pas de compte PHPfrance

25 juin 2010, 21:52

Tout compte fait, en ouvrant mon .xml téléchargé, il ne marche pas..
En l'ouvrant dans le bloc-notes:

<br />
<b>Warning</b>: readfile() [<a href='http://www.php.net/function.readfile'>f ... eadfile</a>]: open_basedir restriction in effect. File(/data/www/antipubs/Pubs.xml) is not within the allowed path(s): (../../.:/data/tmp) in <b>/data2/www/monsite/antipubs/dl_pubs.php</b> on line <b>11</b><br />
<br />
<b>Warning</b>: readfile(/data/www/antipubs/Pubs.xml) [<a href='http://www.php.net/function.readfile'>f ... eadfile</a>]: failed to open stream: Operation not permitted in <b>/data2/www/monsite/antipubs/dl_pubs.php</b> on line <b>11</b><br />

Snake38_invite
Invité n'ayant pas de compte PHPfrance

25 juin 2010, 22:23

Problème résolu:
Fichier php fonctionnel:

Code : Tout sélectionner

<?php $full_path = 'Pubs.xml'; $file_name = basename($full_path); ini_set('zlib.output_compression', 0); $date = gmdate(DATE_RFC1123); header('Pragma: public'); header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Content-Tranfer-Encoding: none'); header('Content-Length: '.filesize($full_path)); header('Content-MD5: '.base64_encode(md5_file($full_path))); header('Content-Type: application/octetstream; name="'.$file_name.'"'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); header('Date: '.$date); header('Expires: '.gmdate(DATE_RFC1123, time()+1)); header('Last-Modified: '.gmdate(DATE_RFC1123, filemtime($full_path))); readfile($full_path); exit; ?>

nonozor
Invité n'ayant pas de compte PHPfrance

28 sept. 2010, 10:07

Problème résolu:
Fichier php fonctionnel:

Code : Tout sélectionner

<?php $full_path = 'Pubs.xml'; $file_name = basename($full_path); ini_set('zlib.output_compression', 0); $date = gmdate(DATE_RFC1123); header('Pragma: public'); header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Content-Tranfer-Encoding: none'); header('Content-Length: '.filesize($full_path)); header('Content-MD5: '.base64_encode(md5_file($full_path))); header('Content-Type: application/octetstream; name="'.$file_name.'"'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); header('Date: '.$date); header('Expires: '.gmdate(DATE_RFC1123, time()+1)); header('Last-Modified: '.gmdate(DATE_RFC1123, filemtime($full_path))); readfile($full_path); exit; ?>
Peut-on savoir comment tu as résolu ton problème de droits ?
Ça m'intéresse!

Merci.