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

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RÉSOLU] Script forcer téléchargement: marche pas

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

par nonozor » 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.

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

par Snake38_invite » 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; ?>

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

par Snake38_invite » 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 />

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

par Snake38_invite » 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 ?

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

par stealth35 » 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

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

par Snake38_invite » 24 juin 2010, 17:07

Ne marche pas non plus..

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

par stealth35 » 24 juin 2010, 13:04

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

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

par Snake38 » 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