Тема: IdHTTPServer
Показать сообщение отдельно
  #4  
Старый 05.09.2009, 16:52
Аватар для Casper-Hacker
Casper-Hacker Casper-Hacker вне форума
Начинающий
 
Регистрация: 19.05.2008
Сообщения: 147
Версия Delphi: x
Репутация: 15
По умолчанию

Код:
procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
//INDEX
if (ARequestInfo.Document='') or (ARequestInfo.Document='/') then begin
AResponseInfo.ContentType:='text/html';
IdHTTPServer1.ServeFile(AThread, AResponseinfo,Edit2.Text+'\'+Edit1.Text) end else
//ERROR 404
if (ARequestInfo.Document<>'') or (ARequestInfo.Document<>'/') then
if fileexists(Edit2.Text+'\'+ARequestInfo.Document)=false then
IdHTTPServer1.ServeFile(AThread, AResponseinfo,Edit2.Text+'\'+Edit3.Text) else
//CONTENT TYPE
begin
if Pos('.GIF',ANSIUPPERCASE(ARequestInfo.Document))>0 then AResponseInfo.ContentType:='image/gif'
else if Pos('.JPG',ANSIUPPERCASE(ARequestInfo.Document))>0 then AResponseInfo.ContentType:='image/jpg'
else if Pos('.JPEG',ANSIUPPERCASE(ARequestInfo.Document))>0 then AResponseInfo.ContentType:='image/jpeg'
else if Pos('.BMP',ANSIUPPERCASE(ARequestInfo.Document))>0 then AResponseInfo.ContentType:='image/bmp'
else if Pos('.PNG',ANSIUPPERCASE(ARequestInfo.Document))>0 then AResponseInfo.ContentType:='image/png'
else if (Pos('.HTML',ANSIUPPERCASE(ARequestInfo.Document))>0) or
(Pos('.HTM',ANSIUPPERCASE(ARequestInfo.Document))>0) or
(Pos('.PHP',ANSIUPPERCASE(ARequestInfo.Document))>0) or
(Pos('.CSS',ANSIUPPERCASE(ARequestInfo.Document))>0) or
(Pos('.TXT',ANSIUPPERCASE(ARequestInfo.Document))>0) or
(Pos('.XML',ANSIUPPERCASE(ARequestInfo.Document))>0) or
(Pos('.JS',ANSIUPPERCASE(ARequestInfo.Document))>0) then AResponseInfo.ContentType:='text/html'
else AResponseInfo.ContentType:='application/octet-stream';
IdHTTPServer1.ServeFile(AThread, AResponseinfo,Edit2.Text+'\'+ARequestInfo.Document);
end;

Edit2 - это путь главного каталога. Edit1 - это главный файл (index.htm, index.php). Edit3 - это файл ошибки 404.
Ответить с цитированием