Page 1 sur 1

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

Posté : 24 juin 2010, 11:59
par Snake38
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

Re: Script forcer téléchargement: marche pas

Posté : 24 juin 2010, 13:04
par stealth35
met juste ca en header
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'.$file_name.'"');

Re: Script forcer téléchargement: marche pas

Posté : 24 juin 2010, 17:07
par Snake38_invite
Ne marche pas non plus..

Re: Script forcer téléchargement: marche pas

Posté : 24 juin 2010, 17:09
par stealth35
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

Re: Script forcer téléchargement: marche pas

Posté : 25 juin 2010, 21:40
par Snake38_invite
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 ?

Re: Script forcer téléchargement: marche pas

Posté : 25 juin 2010, 21:52
par Snake38_invite
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 />

Re: Script forcer téléchargement: marche pas

Posté : 25 juin 2010, 22:23
par Snake38_invite
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; ?>

Re: Script forcer téléchargement: marche pas

Posté : 28 sept. 2010, 10:07
par nonozor
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.