was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

49 Visitors Online


 
...den MIME Typ einer Datei ermitteln?
Autor: James Caldwell
[ Tip ausdrucken ]  

Tip Bewertung (26):  
     


{
This code is useful if you are creating a webserver program.
It's very simple, just input the extension of a file and the
function returns the MIME type of that file.

mimetypes.RES is the compiled resource file that contains a string
table with 641 different MIME types.
http://modelingman.freeprohost.com/Downloads/Delphi/MIME/mimetypes.RES

mimetypes.rc is the source file of mimetypes.RES, you can add more
types to this and compile it using brcc32
http://modelingman.freeprohost.com/Downloads/Delphi/MIME/mimetypes.rc
}

{$R mimetypes.RES}

function GetMIMEType(FileExt: string): string;
var
  
I: Integer;
  S: array[0..255] of Char;
const
  
MIMEStart = 101;
  // ID of first MIME Type string (IDs are set in the .rc file
  // before compiling with brcc32)
  
MIMEEnd = 742; //ID of last MIME Type string
begin
  
Result := 'text/plain';
  // If the file extenstion is not found then the result is plain text
  
for I := MIMEStart to MIMEEnd do
  begin
    
LoadString(hInstance, I, @S, 255);
    // Loads a string from mimetypes.res which is embedded into the
    // compiled exe
    
if Copy(S, 1, Length(FileExt)) = FileExt then
    
// "If the string that was loaded contains FileExt then"
    
begin
      
Result := Copy(S, Length(FileExt) + 2, 255);
      // Copies the MIME Type from the string that was loaded
      
Break;
      // Breaks the for loop so that it won't go through every
      // MIME Type after it found the correct one.
    
end;
  end;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners