请大家提供学习用Delphi开发CGI程序的教程、资料。(200分)

  • 主题发起人 主题发起人 cgh0717
  • 开始时间 开始时间
C

cgh0717

Unregistered / Unconfirmed
GUEST, unregistred user!
[:)]想要学啊。所以请帮帮忙。谢谢。
分数还是太少了,所以只好出200而已了。
 
李维的<分布式应用电子商务篇>;
 
楼上说的好,李维我喜欢
 
喔。我有,只是,我想知道。要不要看李维的TCP/IP开发那本书???
我想找些网上的资料。[:D]
 
你把E-MAIL给我,我可以给你发个例子
 
delphi作cgi,好像没有几家公司用这种方案哦
 
为什么不试试呢???我的信箱是:cgh0717@sina.com[:)]
 
CSDN 上有不少文档
http://www.comprg.com.cn/
http://www.cug.edu.cn/fwzn/wlzx/wlfw/
http://coldease.myetang.com/index.htm
http://www.codelphi.com/
http://delphi.mychangshu.com/
网上东西多的是
搜一下就无数
只在于你有多少时间来看了
 
我找过啊,只是没有找到而已。[:(]
 
csdn上有好多呢
 
标准输入输出
 
csdn有一大块文章,专讲delphi和cgi
 
[blue]对,CSDN上有很多文章的.[:D]
http://www.csdn.net/develop/list_article.asp?bigclassid=2
http://www.comprg.com.cn/
http://www.cug.edu.cn/fwzn/wlzx/wlfw/
http://coldease.myetang.com/index.htm
http://www.codelphi.com/
http://delphi.mychangshu.com/ [:D][/blue]
 
给你一套完整的例子! Delphi代码+CGI

program Cgitest;

{$APPTYPE CONSOLE}

uses
Windows, Sysutils, Filectrl;

{$R *.RES}

Var
TempURL, // Temp URLencoded string
RawURL, // Raw input string URLencoded
DecURL: String; // Decoded input string
Index: Integer; // Global index to URL string
Temp,
Filepath, // Path of Output file
Outname: String; // Path and file name of output file
Tfile: Text; // Output file

// Get a single character from TempURL string
Function GetURLchar: Char;
Begin
If Index<=Length(TempURL) then // If index is ok
Result := TempURL[Index] // Return a char
else
Result := ' '; // Return space if error
Inc(Index);
end;

// Converts a hex character (0 to F) to an integer (0 to 15)
Function Hex2Int(Inch: Char): Integer;
Begin
Result := 0; // Return 0 if invalid character
If Inch in ['A'..'F'] then
Result := Ord(Inch)-$37;
If Inch in ['a'..'f'] then
Result := Ord(Inch)-$57;
If Inch in ['0'..'9'] then
Result := Ord(Inch)-$30;
end;

// Converts a URLencoded string to a normal string
Function DecodeURL(Instr: String): String;
Var
S: String;
X: Integer;
C,N1,N2: Char;
Begin
If Instr='' then exit;
S := '';
TempURL := Instr; // Copy URLencoded string
Index := 1; // Reset string index
Repeat
C := GetURLchar; // Get next character
If C='%' then // If it's a hex esc char
Begin
N1 := GetURLchar; // Get first digit
N2 := GetURLchar; // Get second digit
X := (Hex2Int(N1)*16)+Hex2Int(N2); // Convert to integer
S := S+Chr(X); // Add character
end else
If C='+' then // If + then convert to space
S := S+' ' else
S := S+C; // Just add character
Until C=' '; // Until no more in string
Result := S;
end;

Procedure Findfilename(Cstring: String);
Var
P, // Index of start of param/value pair
E, // Index of end of param/value pair
L, // Length of Cstring
EQ: Integer; // Position of equals sign
NV, // Name value pair
Name,
Value,
S: String; // Substring which gradually gets shorter as we parse
Begin
L := Length(Cstring);
P := 0;
S := Cstring; // Set up Temp string for 1st pass
Repeat
S := Copy(S,P+1,L); // Get substring from &+1
E := Pos('&',S); // Find next &
If E>0 then // If another & found
NV := Copy(S,1,E-1) // Get name/value pair
else // If no more after this
NV := Copy(S,1,L); // Get last one
EQ := Pos('=',NV); // Find =
If EQ>0 then // If it's there
Begin
Name := Copy(NV,1,EQ-1); // Extract name
Value := Copy(NV,EQ+1,L); // Extract value
If Uppercase(Name)='FILENAME' then // If we've found it
Begin
Outname := Value; // Set output file name
exit; // Dont check any more
end;
end;
If E>0 then P := E; // If more to do set start of next one
Until E=0; // Until no more &'s
end;

// Write all URLencoded name/value pairs in Cstring to a file
Procedure Writefile(Cstring: String);
Var
P, // Index of start of param/value pair
E, // Index of end of param/value pair
L, // Length of Cstring
EQ: Integer; // Position of equals sign
NV, // Name value pair
Name,
Value,
Tmp,
S: String; // Substring which gradually gets shorter as we parse
Begin
L := Length(Cstring);
P := 0;
S := Cstring; // Set up Temp string for 1st pass
Repeat
S := Copy(S,P+1,L); // Get substring from &+1
E := Pos('&',S); // Find next &
If E>0 then // If another & found
NV := Copy(S,1,E-1) // Get name/value pair
else // If no more after this
NV := Copy(S,1,L); // Get last one
EQ := Pos('=',NV); // Find =
If EQ>0 then // If it's there
Begin
Name := Copy(NV,1,EQ-1); // Extract name
Value := Copy(NV,EQ+1,L); // Extract value
If Uppercase(Name)<>'FILENAME' then // If it's anything but filename
Begin
If Value<>'' then
Tmp := DecodeURL(Value) // Decode value string
else
Tmp := '';
Writeln(Name+': '+Tmp+'<br>'); // Write to stdout
Writeln(Tfile, Name+': '+Tmp); // and to file
end;
end;
If E>0 then P := E; // If more to do set start of next one
Until E=0; // Until no more &'s
end;

// Start of main program
begin
Readln(RawURL); // Read the URLencoded string from Web server
//RawURL:='Filename=C%3A%5Cwww%5CIntranet%5CTest%5CTestfile.txt&Name=Testname&damn=&Comments=Test+Comment';
DecURL := DecodeURL(RawURL); // Convert to "normal" text
Outname := ''; // Reset out file name
Findfilename(DecURL); // Try to find file name
If Outname<>'' then // If we have a filename
Begin
Filepath := ExtractFiledir(Outname); // Get path of file
If DirectoryExists(Filepath) then // If folder exists
Begin
If Fileexists(Filepath+'/Head.htm') then // If header file
Begin
Assignfile(Tfile, Filepath+'/Head.htm'); // Assign the file
Reset(Tfile); // Reset it
While not Eof(Tfile) do // For whole file
Begin
Readln(Tfile, Temp); // Read a line
Writeln(Temp); // Write to stdout
end;
Close(Tfile);
end;
// Writeln('Raw URL was '+RawURL); // For debugging
// Writeln('Decoded URL was '+DecURL);
Assignfile(Tfile, Outname); // Assign file name
If Fileexists(Outname) then // If it exists
Append(Tfile) // Append to it
else // Otherwise create a new one
Rewrite(Tfile);
Writefile(RawURL); // Write all the values
Writeln(Tfile, '----------------------------------------');
Closefile(Tfile); // Close the file
Writeln('<br><b>Data successfully written to '+
Outname+'</b>');
If Fileexists(Filepath+'/Tail.htm') then // If header file
Begin
Assignfile(Tfile, Filepath+'/Tail.htm'); // Assign the file
Reset(Tfile); // Reset it
While not Eof(Tfile) do // For whole file
Begin
Readln(Tfile, Temp); // Read a line
Writeln(Temp); // Write to stdout
end;
Close(Tfile);
end;
end else
Writeln('<br><b>ERROR - Invalid file folder '+
Filepath+'</b>');
end;
end.

 
HTML SAMPLE SOURCE
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.5 [en] (Win95; I) [Netscape]">
<title>TEST LOG</title>
</head>
<body>
<h2>TEST LOG</h2>
Enter Information in the form below:.
<br><form method="POST" action="/cgi-bin/cgitest.exe">
<input type="hidden" name="Filename" size="44" value="C:/Xitami/Webpages/Docs/Sitelog/Sitelog.txt">
<table BORDER=0 >
<tr>
<td>Enter Your Name:
<br><input type="text" name="Name" size="20"></td>
<td>Date:
<br><input type="text" name="Date" size="20"></td>
<td>Time:
<br><input type="text" name="Time" size="20"></td>
</tr>
</table>
<p><b>DETAILS:</b>
<textarea name="Details" rows="8" cols="70" wrap="hard"></textarea>
<p><input type="submit" value="Submit Form"><input type="reset" value="Clear Form">
<br></form>
<hr>
</body>
</html>
 
多人接受答案了。
 

Similar threads

后退
顶部