Retourne le Content-Type correspondant à  un fichier

  Information

Cette fonction retourne l'en-tête Content-Type correspondante à votre fichier.

Passer le nom de votre fichier en argument dans le fonction, ensuite le code récupère l'extension du fichier, la passe en Majuscule et fait le test puis retourne l'en-tête Content-Type correpondante à votre fichier.

  code source classé dans  Mail - Emailing

 
 01    
 02    
 03    
 04    
 05    
 06    
 07    
 08    
 09    
 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    
 70    
 71    
 72    
 73    
 74    
 75    
 76    
 77    
 78    
 79    
 80    
 81    
 82    
 83    
 84    
 85    
 86    
 87    
 88    
 89    
 90    
 91    
 92    
 93    
 94    
 95    
 96    
 97    
 98    
 99    
 100    
 101    
 102    
 103    
 104    
 105    
 106    
 107    
 108    
 109    
 110    
 111    
 112    
 113    
 114    
 115    
                               
<?php
/*---------------------------------------------------------------*/
/*
    Titre : Retourne le Content-Type correspondant à un fichier                                                          
                                                                                                                          
    URL   : https://phpsources.net/code_s.php?id=58
    Auteur           : Mathieu                                                                                            
    Date édition     : 01 Sept 2004                                                                                       
    Date mise à jour : 26 Sept 2019                                                                                      
    Rapport de la maj:                                                                                                    
    - fonctionnement du code vérifié                                                                                    
*/
/*---------------------------------------------------------------*/

  function GetMIME($ext){
  $ext=strrchr($ext,".");
  switch(strtoupper($ext)){
  case ".DWG":    return "application/acad;";      break;
  case ".CCAD":   return "application/clariscad;"; break;
  case ".DRW":    return "application/drafting;";  break;
  case ".DXF":    return "application/dxf;";       break;
  case ".UNV":    return "application/i-deas;";    break;
  case ".IGS":    return "application/iges;";      break;
  case ".IGES":   return "application/iges;";      break;
  case ".ODA":    return "application/oda;";       break;
  case ".PDF":    return "application/pdf;";       break;
  case ".AI":     return "application/postscript;";break;
  case ".PS":     return "application/postscript;";break;
  case ".EPS":    return "application/postscript;";break;
  case ".PRT":    return "application/pro_eng;";   break;
  case ".RTF":    return "application/rtf;";       break;
  case ".SET":    return "application/set;";       break;
  case ".STL":    return "application/sla;";       break;
  case ".SOL":    return "application/solids;";    break;
  case ".STEP":   return "application/STEP;";      break;
  case ".STP":    return "application/STEP;";      break;
  case ".VDA":    return "application/vda;";       break;
  case ".MIF":    return "application/x-mif;";     break;
  case ".CSH":    return "application/x-csh;";     break;
  case ".DVI":    return "application/x-dvi;";     break;
  case ".HDF":    return "application/x-hdf;";     break;
  case ".LATEX":  return "application/x-latex;";   break;
  case ".CDF":    return "application/x-netcdf;";  break;
  case ".NC":     return "application/x-netcdf;";  break;
  case ".SH":     return "application/x-sh;";      break;
  case ".TCL":    return "application/x-tcl;";     break;
  case ".TEX":    return "application/x-tex;";     break;
  case ".TEXI":   return "application/x-texinfo;"; break;
  case ".TEXINFO":return "application/x-texinfo;"; break;
  case ".TR":     return "application/x-troff;";   break;
  case ".ROFF":   return "application/x-troff;";   break;
  case ".T":      return "application/x-troff;";   break;
  case ".MAN":    return "application/x-troff-man;";break;
  case ".ME":     return "application/x-troff-me;";break;
  case ".MS":     return "application/x-troff-ms;";break;
  case ".SRC":    return "application/x-wais-source;";break;
  case ".ZIP":    return "application/zip;";       break;
  case ".BCPIO":  return "application/x-bcpio;";   break;
  case ".CPIO":   return "application/x-cpio;";    break;
  case ".GTAR":   return "application/x-gtar;";    break;
  case ".SHAR":   return "application/x-shar;";    break;
  case ".SV4CPIO":return "application/x-sv4cpio;"; break;
  case ".SV4CRC"return "application/x-sv4crc;";  break;
  case ".TAR":    return "application/x-tar;";     break;
  case ".USTAR":  return "application/x-ustar;";   break;
  case ".AU":     return "audio/basic;";           break;
  case ".SND":    return "audio/basic;";           break;
  case ".AIF":    return "audio/x-aiff;";          break;
  case ".AIFF":   return "audio/x-aiff;";          break;
  case ".AIFC":   return "audio/x-aiff;";          break;
  case ".WAV":    return "audio/x-wav;";           break;
  case ".GIF":    return "image/gif;";             break;
  case ".IEF":    return "image/ief;";             break;
  case ".JPG":    return "image/jpeg;";            break;
  case ".JPEG":   return "image/jpeg;";        break;
  case ".JPE":    return "image/jpeg;";        break;
  case ".TIFF":   return "image/tiff;";        break;
  case ".TIF":    return "image/tiff;";        break;
  case ".RAS":    return "image/x-cmu-raster;";      break;
  case ".PNM":    return "image/x-portable-anymap;"; break;
  case ".PBM":    return "image/x-portable-bitmap;"; break;
  case ".PGM":    return "image/x-portable-graymap;";break;
  case ".PPM":    return "image/x-portable-pixmap;"; break;
  case ".RGB":    return "image/x-rgb;";          break;
  case ".XBM":    return "image/x-xbitmap;";      break;
  case ".XPM":    return "image/x-xpixmap;";      break;
  case ".XWD":    return "image/x-xwindowdump;";  break;
  case ".ZIP":    return "multipart/x-zip;";      break;
  case ".GZIP":   return "multipart/x-gzip;";      break;
  case ".HTM":    return "text/html; charset=\"iso-8859-1\";";   break;
  case ".HTML":   return "text/html; charset=\"iso-8859-1\";";   break;
  case ".G":      return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".H":      return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".C":      return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".CC":     return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".HH":     return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".M":      return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".F90":    return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".TXT":    return "text/plain; charset=\"iso-8859-1\";";  break;
  case ".TRX":    return "text/richtext;";      break;
  case ".TSV":    return "text/tab-separated-values;";break;
  case ".ETX":    return "text/x-setext;";     break;
  case ".MPG":    return "video/mpeg;";        break;
  case ".MPE":    return "video/mpeg;";        break;
  case ".MPEG":   return "video/mpeg;";        break;
  case ".QT":     return "video/quicktime;";   break;
  case ".MOV":    return "video/quicktime;";   break;
  case ".AVI":    return "video/x-msvideo;";   break;
  case ".MOVIE":  return "video/x-sgi-movie;"; break;
  default:        return "application/octet-stream;"; break;
  }
}
?>

Exemple :

 
 01    
 02    
 03    
 04    
 05    
 06    
 07    
 08    
                                
<?php

    echo GetMIME('img.jpg');   // image/jpeg;text/html;
    echo GetMIME('file.html'); // charset="iso-8859-1";
    echo GetMIME('video.avi'); // video/x-msvideo;
?>

          Fonctions du code - Doc officielle PHP

   php.net   Description Versions PHP OUTIL
   echo Affiche une chaîne de caractères PHP 4, PHP 5, PHP 7, PHP 8
   return Retourne le controle du programme au module appelant. PHP 4, PHP 5, PHP 7, PHP 8
   strrchr Trouve la dernière occurrence d'un caractère dans une chaîne PHP 4, PHP 5, PHP 7, PHP 8
   strtoupper Renvoie une chaîne en majuscules PHP 4, PHP 5, PHP 7, PHP 8

   Dites merci aux auteurs pour leurs travail, ça ne coûte rien et ça fait toujours plaisir wink

 Autres snippets qui pourraient vous intéressez

Affiche l'IP correspondant à un nom de domaine

Compatibilité : PHP 5, PHP 7

Retourne l'adresse IP dans un tableau correspondant au Nom du Domaine passée en argument dans la fonction. Veillez à ne pas mettre de protocoles dans la fonction.

SEO PHP Anti duplicate content

Compatibilité : PHP 5, PHP 7

Fonction qui vérifie qu'1 texte n'est pas déjà présent sur le net en récupérant le résultat d'une recherche sur Google Search

Connaitre avec PHP le type de navigateur

Compatibilité : PHP 5, PHP 7

Connaitre le type de navigateur du client avec la fonction getenv () qui retourne la valeur d'une variable d'environnement.

Envoyer un mail type MINE en HTML - PHP Sources

Compatibilité : PHP 5, PHP 7

L'une des taches les plus communes pour un programmeur PHP est qu'il doit faire face au développement d'applications qui envoient des mails MIME.

Multi Upload de fichiers

Compatibilité : PHP 5, PHP 7

Transférer plusieurs fichiers en même temps sur votre serveur. Tout type de fichiers.

Présentation de PHP

PHP débutant et initié 50 Tutoriel

Présentation de MySQL

avatar

Mathieu

  01 Sept 2004

  SOURCE   Télécharger

Information sur les mises à jour

Dernière mise à jour :

    26 Sept 2019
    fonctionnement du code vérifié

9 507 Vues
Compatibilité
PHP 5, 7 et 8+