Return to Snippet

Revision: 5023
at February 6, 2008 04:21 by fabian


Initial Code
function addMime(){

/*
	source types: http://de.selfhtml.org/diverses/mimetypen.htm
	
	CREATE TABLE `mime` (                                                   
          `file_extension` varchar(10) collate latin1_general_ci default NULL,  
          `file_mime` varchar(255) collate latin1_general_ci default NULL,      
          `file_mime_type` varchar(255) collate latin1_general_ci default NULL  
        )
        
*/



$txt=<<< END
application/acad 	*.dwg 	AutoCAD-Dateien (nach NCSA)
application/applefile 	  	AppleFile-Dateien
application/astound 	*.asd *.asn 	Astound-Dateien
application/dsptype 	*.tsp 	TSP-Dateien
application/dxf 	*.dxf 	AutoCAD-Dateien (nach CERN)
application/futuresplash 	*.spl 	Flash Futuresplash-Dateien
application/gzip 	*.gz 	GNU Zip-Dateien
application/listenup 	*.ptlk 	Listenup-Dateien
application/mac-binhex40 	*.hqx 	Macintosh Binärdateien
application/mbedlet 	*.mbd 	Mbedlet-Dateien
application/mif 	*.mif 	FrameMaker Interchange Format Dateien
application/msexcel 	*.xls *.xla 	Microsoft Excel Dateien
application/mshelp 	*.hlp *.chm 	Microsoft Windows Hilfe Dateien
application/mspowerpoint 	*.ppt *.ppz *.pps *.pot 	Microsoft Powerpoint Dateien
application/msword 	*.doc *.dot 	Microsoft Word Dateien
application/octet-stream 	*.bin *.exe *.com *.dll *.class 	Ausführbare Dateien
application/oda 	*.oda 	Oda-Dateien
application/pdf 	*.pdf 	Adobe PDF-Dateien
application/postscript 	*.ai *.eps *.ps 	Adobe PostScript-Dateien
application/rtc 	*.rtc 	RTC-Dateien
application/rtf 	*.rtf 	Microsoft RTF-Dateien
application/studiom 	*.smp 	Studiom-Dateien
application/toolbook 	*.tbk 	Toolbook-Dateien
application/vocaltec-media-desc 	*.vmd 	Vocaltec Mediadesc-Dateien
application/vocaltec-media-file 	*.vmf 	Vocaltec Media-Dateien
application/xhtml+xml 	*.htm *.html *.shtml *.xhtml 	XHTML-Dateien
application/xml 	*.xml 	XML-Dateien
application/x-bcpio 	*.bcpio 	BCPIO-Dateien
application/x-compress 	*.z 	zlib-komprimierte Dateien
application/x-cpio 	*.cpio 	CPIO-Dateien
application/x-csh 	*.csh 	C-Shellscript-Dateien
application/x-director 	*.dcr *.dir *.dxr 	Macromedia Director-Dateien
application/x-dvi 	*.dvi 	DVI-Dateien
application/x-envoy 	*.evy 	Envoy-Dateien
application/x-gtar 	*.gtar 	GNU tar-Archivdateien
application/x-hdf 	*.hdf 	HDF-Dateien
application/x-httpd-php 	*.php *.phtml 	PHP-Dateien
application/x-javascript 	*.js 	serverseitige JavaScript-Dateien
application/x-latex 	*.latex 	LaTeX-Quelldateien
application/x-macbinary 	*.bin 	Macintosh Binärdateien
application/x-mif 	*.mif 	FrameMaker Interchange Format Dateien
application/x-netcdf 	*.nc *.cdf 	Unidata CDF-Dateien
application/x-nschat 	*.nsc 	NS Chat-Dateien
application/x-sh 	*.sh 	Bourne Shellscript-Dateien
application/x-shar 	*.shar 	Shell-Archivdateien
application/x-shockwave-flash 	*.swf *.cab 	Flash Shockwave-Dateien
application/x-sprite 	*.spr *.sprite 	Sprite-Dateien
application/x-stuffit 	*.sit 	Stuffit-Dateien
application/x-supercard 	*.sca 	Supercard-Dateien
application/x-sv4cpio 	*.sv4cpio 	CPIO-Dateien
application/x-sv4crc 	*.sv4crc 	CPIO-Dateien mit CRC
application/x-tar 	*.tar 	tar-Archivdateien
application/x-tcl 	*.tcl 	TCL Scriptdateien
application/x-tex 	*.tex 	TeX-Dateien
application/x-texinfo 	*.texinfo *.texi 	Texinfo-Dateien
application/x-troff 	*.t *.tr *.roff 	TROFF-Dateien (Unix)
application/x-troff-man 	*.man *.troff 	TROFF-Dateien mit MAN-Makros (Unix)
application/x-troff-me 	*.me *.troff 	TROFF-Dateien mit ME-Makros (Unix)
application/x-troff-ms 	*.me *.troff 	TROFF-Dateien mit MS-Makros (Unix)
application/x-ustar 	*.ustar 	tar-Archivdateien (Posix)
application/x-wais-source 	*.src 	WAIS Quelldateien
application/x-www-form-urlencoded 	  	HTML-Formulardaten an CGI
application/zip 	*.zip 	ZIP-Archivdateien
audio/basic 	*.au *.snd 	Sound-Dateien
audio/echospeech 	*.es 	Echospeed-Dateien
audio/tsplayer 	*.tsi 	TS-Player-Dateien
audio/voxware 	*.vox 	Vox-Dateien
audio/x-aiff 	*.aif *.aiff *.aifc 	AIFF-Sound-Dateien
audio/x-dspeeh 	*.dus *.cht 	Sprachdateien
audio/x-midi 	*.mid *.midi 	MIDI-Dateien
audio/x-mpeg 	*.mp2 	MPEG-Dateien
audio/x-pn-realaudio 	*.ram *.ra 	RealAudio-Dateien
audio/x-pn-realaudio-plugin 	*.rpm 	RealAudio-Plugin-Dateien
audio/x-qt-stream 	*.stream 	Quicktime-Streaming-Dateien
audio/x-wav 	*.wav 	WAV-Dateien
drawing/x-dwf 	*.dwf 	Drawing-Dateien
image/cis-cod 	*.cod 	CIS-Cod-Dateien
image/cmu-raster 	*.ras 	CMU-Raster-Dateien
image/fif 	*.fif 	FIF-Dateien
image/gif 	*.gif 	GIF-Dateien
image/ief 	*.ief 	IEF-Dateien
image/jpeg 	*.jpeg *.jpg *.jpe 	JPEG-Dateien
image/png 	*.png 	PNG-Dateien
image/tiff 	*.tiff *.tif 	TIFF-Dateien
image/vasa 	*.mcf 	Vasa-Dateien
image/vnd.wap.wbmp 	*.wbmp 	Bitmap-Dateien (WAP)
image/x-freehand 	*.fh4 *.fh5 *.fhc 	Freehand-Dateien
image/x-icon 	*.ico 	Icon-Dateien (z.B. Favoriten-Icons)
image/x-portable-anymap 	*.pnm 	PBM Anymap Dateien
image/x-portable-bitmap 	*.pbm 	PBM Bitmap Dateien
image/x-portable-graymap 	*.pgm 	PBM Graymap Dateien
image/x-portable-pixmap 	*.ppm 	PBM Pixmap Dateien
image/x-rgb 	*.rgb 	RGB-Dateien
image/x-windowdump 	*.xwd 	X-Windows Dump
image/x-xbitmap 	*.xbm 	XBM-Dateien
image/x-xpixmap 	*.xpm 	XPM-Dateien
message/external-body 	  	Nachricht mit externem Inhalt
message/http 	  	HTTP-Headernachricht
message/news 	  	Newsgroup-Nachricht
message/partial 	  	Nachricht mit Teilinhalt
message/rfc822 	  	Nachricht nach RFC 2822
model/vrml 	*.wrl 	Visualisierung virtueller Welten (VRML)
multipart/alternative 	  	mehrteilige Daten gemischt
multipart/byteranges 	  	mehrteilige Daten mit Byte-Angaben
multipart/digest 	  	mehrteilige Daten / Auswahl
multipart/encrypted 	  	mehrteilige Daten verschlüsselt
multipart/form-data 	  	mehrteilige Daten aus HTML-Formular (z.B. File-Upload)
multipart/mixed 	  	mehrteilige Daten gemischt
multipart/parallel 	  	mehrteilige Daten parallel
multipart/related 	  	mehrteilige Daten / verbunden
multipart/report 	  	mehrteilige Daten / Bericht
multipart/signed 	  	mehrteilige Daten / bezeichnet
multipart/voice-message 	  	mehrteilige Daten / Sprachnachricht
text/comma-separated-values 	*.csv 	kommaseparierte Datendateien
text/css 	*.css 	CSS Stylesheet-Dateien
text/html 	*.htm *.html *.shtml 	HTML-Dateien
text/javascript 	*.js 	JavaScript-Dateien
text/plain 	*.txt 	reine Textdateien
text/richtext 	*.rtx 	Richtext-Dateien
text/rtf 	*.rtf 	Microsoft RTF-Dateien
text/tab-separated-values 	*.tsv 	tabulator-separierte Datendateien
text/vnd.wap.wml 	*.wml 	WML-Dateien (WAP)
application/vnd.wap.wmlc 	*.wmlc 	WMLC-Dateien (WAP)
text/vnd.wap.wmlscript 	*.wmls 	WML-Scriptdateien (WAP)
application/vnd.wap.wmlscriptc 	*.wmlsc 	WML-Script-C-dateien (WAP)
text/xml 	*.xml 	XML-Dateien
text/xml-external-parsed-entity 	  	extern geparste XML-Dateien
text/x-setext 	*.etx 	SeText-Dateien
text/x-sgml 	*.sgm *.sgml 	SGML-Dateien
text/x-speech 	*.talk *.spc 	Speech-Dateien
video/mpeg 	*.mpeg *.mpg *.mpe 	MPEG-Dateien
video/quicktime 	*.qt *.mov 	Quicktime-Dateien
video/vnd.vivo 	*.viv *.vivo 	Vivo-Dateien
video/x-msvideo 	*.avi 	Microsoft AVI-Dateien
video/x-sgi-movie 	*.movie 	Movie-Dateien
workbook/formulaone 	*.vts *.vtts 	FormulaOne-Dateien
x-world/x-3dmf 	*.3dmf *.3dm *.qd3d *.qd3 	3DMF-Dateien
x-world/x-vrml 	*.wrl 	Visualisierung virtueller Welten (VRML) (veralteter MIME-Typ, aktuell ist model/vrml)
END;

	$types=explode("\n", $txt);
	foreach($types as $type){
		$parts=explode("	", $type);
		$parts[1]=trim($parts[1]);
		
		if(!$parts[1])	## no file extension specified
			continue;
		
		if(strpos($parts[1], " ")>0){	## more than one file extension
			$extensions=explode(" ", $parts[1]);
			
			foreach($extensions as $extension){
				$filetype=explode(".", $extension);
				$filetype[1]=str_replace("*", "", $filetype[1]);
				$add[]='("'.trim($parts[0]).'", "'.trim($filetype[1]).'", "'.trim($parts[2]).'")';
			}
			
		}
		else{	## only one file extension
			$filetype=explode(".", $parts[1]);
			$filetype[1]=str_replace("*", "", $filetype[1]);
			$add[]='("'.trim($parts[0]).'", "'.trim($filetype[1]).'", "'.trim($parts[2]).'")';
		}
	}
	$sql='insert into `mime` (`file_mime`, `file_extension`, `file_mime_type`) values '.implode(",<br/> ", $add);
	echo $sql.";";

}

Initial URL


Initial Description
PHP function that creates a mySQL INSERT statement for mime types. Type are extracted from a text file.

Initial Title
mySQL MIME Table (PHP)

Initial Tags
mysql, php

Initial Language
PHP