IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Télécharger fichier PHP en PHP


Sujet :

Langage PHP

  1. #1
    Membre habitué
    Inscrit en
    Mai 2008
    Messages
    317
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 317
    Points : 135
    Points
    135
    Par défaut Télécharger fichier PHP en PHP
    Bonjours à tous.
    je suis en ce moment en train de faire un script de gestion de fichier sur serveur grâce à php.
    je peux déjà me balader dans les dossiers etc... mais voila:

    1) je cherche un moyen de faire télécharger des fichiers php
    2) je cherche à savoir s'il y aurait un moyen de pouvoir faire télécharger n'importe quel type de fichier; je veux dire sans avoir a préciser "pour tel type, tu fait ça, pour tel autre type tu fais ça etc...

    Merci d'avance.

  2. #2
    Membre habitué
    Inscrit en
    Mai 2008
    Messages
    317
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 317
    Points : 135
    Points
    135
    Par défaut
    Désolé ça faisait longtemps que je cherchais mais je pense avoir trouvé.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <?php
    // telechargerFichier(file_get_contents('index.php'), 'test.php');//
    function download_file($contenuFichier, $nomFichier)
    {
    	$typeFichier=typeMime($nomFichier);
    	@ob_end_clean();
    	@ini_set('zlib.output_compression', '0');
    	$maintenant=gmdate('D, d M Y H:i:s').' GMT';
    	header('Content-Type: '.$typeFichier);
    	header('Content-Disposition: attachment; filename="'.$nomFichier.'"');
    	if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT']))   {
    		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    		header('Pragma: public');
    	}
    	else header('Pragma: no-cache');
    	header('Last-Modified: '.$maintenant);
    	header('Expires: '.$maintenant); 
    	header('Content-Length: '.strlen($contenuFichier));
       echo $contenuFichier;
    }
     
    function typeMime($nomFichier)
    {
       if(preg_match("@Opera(/| )([0-9].[0-9]{1,2})@", $_SERVER['HTTP_USER_AGENT'], $resultats))
          $navigateur="Opera";
       elseif(preg_match("@MSIE ([0-9].[0-9]{1,2})@", $_SERVER['HTTP_USER_AGENT'], $resultats))
          $navigateur="Internet Explorer";
       else $navigateur="Mozilla";
       $mime=parse_ini_file("admin/FileAdministrator/mime.ini");
       $extension=substr($nomFichier, strrpos($nomFichier, ".")+1);
       if(array_key_exists($extension, $mime)) $type=$mime[$extension];
       else $type=($navigateur!="Mozilla") ? 'application/octetstream' : 'application/octet-stream';
       return $type;
    }
    ?>
    avec un fichier mime.ini:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    [textes]
    txt = text/plain
    htm = text/html
    html = text/html
    css = text/css
     
    [images]
    png = image/png
    gif = image/gif
    jpg = image/jpeg
    jpeg = image/jpeg
    bmp = image/bmp
    tif = image/tiff
     
    [archives]
    bz2 = application/x-bzip
    gz = application/x-gzip
    tar = application/x-tar
    zip = application/zip
     
    [audio]
    aif = audio/aiff
    aiff = audio/aiff
    mid = audio/mid
    midi = audio/mid
    mp3 = audio/mpeg
    ogg = audio/ogg
    wav = audio/wav
    wma = audio/x-ms-wma
     
    [video]
    asf = video/x-ms-asf
    asx = video/x-ms-asf
    avi = video/avi
    mpg = video/mpeg
    mpeg = video/mpeg
    wmv = video/x-ms-wmv
    wmx = video/x-ms-wmx
     
    [xml]
    xml = text/xml
    xsl = text/xsl
     
    [microsoft]
    doc = application/msword
    rtf = application/msword
    xls = application/excel
    pps = application/vnd.ms-powerpoint
    ppt = application/vnd.ms-powerpoint
     
    [adobe]
    pdf = application/pdf
    ai = application/postscript
    eps = application/postscript
    psd = image/psd
     
    [macromedia]
    swf = application/x-shockwave-flash
     
    [real]
    ra = audio/vnd.rn-realaudio
    ram = audio/x-pn-realaudio
    rm = application/vnd.rn-realmedia
    rv = video/vnd.rn-realvideo
     
    [autres]
    exe = application/x-msdownload
    pls = audio/scpls
    m3u = audio/x-mpegurl
    Je fini mes tests et je passe en résolu.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Excel] Comment lire des fichiers excel avec php?
    Par dear_rihab dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 02/11/2007, 12h38
  2. [PHP-JS] php et fichier
    Par marion782 dans le forum Langage
    Réponses: 8
    Dernier message: 06/12/2005, 00h32
  3. Réponses: 2
    Dernier message: 20/11/2005, 18h54
  4. Réponses: 9
    Dernier message: 29/10/2005, 20h11
  5. [SimpleXML] Comment faire pour transformer un fichier XML en PHP ?
    Par magic8392 dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 23/09/2005, 16h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo