⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 《delphi 7 web 开发及与应用》源码
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp;

type
  TWebModule1 = class(TWebModule)
    procedure WebModule1waDefaultAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure WebModule1waUploadAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  WebModule1: TWebModule1;

implementation

{$R *.DFM}

uses
  MsMultipartParser;

procedure TWebModule1.WebModule1waDefaultAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  Response.Content :=
   '<html>'#13#10 +
   '  <head>'#13#10 +
   '    <title>Multi-File Upload Demo</title>'#13#10 +
   '<link rel="stylesheet" type="text/css" href="http://www.matlus.com/home-styles.css" />'#13#10 +
   '  </head>'#13#10 +
   '<body>'#13#10 +
   '  <form enctype="multipart/form-data" action="' + Request.ScriptName + '/Upload" method="post">'#13#10 +

   '<table class="formbackground" cellpadding="2" cellspacing="2">'#13#10 +
   '<caption class="formcaption"><b>Upload File(s) along with Form fields</b><caption>'#13#10 +

   '  <tr>'#13#10 +
   '    <td class="fieldnames">Person Name</td>'#13#10 +
   '    <td><input name="txtPersonName" type="text" value="" style="width: 200px;"></td>'#13#10 +
   '  </tr>'#13#10 +

   '  <tr>'#13#10 +
   '    <td class="fieldnames">Description of File being uploaded</td>'#13#10 +
   '    <td><input name="txtDescription" type="text" value="" style="width: 300px;"></td>'#13#10 +
   '  </tr>'#13#10 +

   '  <tr>'#13#10 +
   '    <td class="fieldnames">Document</td>'#13#10 +
   '    <td><input name="DocumentBlob" type="file" style="width: 500px;"></td>'#13#10 +
   '  </tr>'#13#10 +

   '  <tr>'#13#10 +
   '    <td colspan="2" align="right"><input type="Submit" value="Send"></td>'#13#10 +
   '  </tr>'#13#10 +

   '</table>'#13#10 +
   '  </form>'#13#10 +
   '</body>' + #13#10 +
   '</html>'#13#10;
end;

procedure TWebModule1.WebModule1waUploadAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  i: Integer;
begin
  with TMsMultipartFormParser.Create do
  begin
    try
      Parse(Request);
      for i := 0 to Files.Count -1 do
        Files[i].SaveToFile(Request.PathTranslated + '\' + ExtractFileName(Files[i].FileName));
      if Files.Count > 0 then
      begin
        Response.Content :=
          '<html>'#13#10 +
          '  <head>'#13#10 +
          '    <title>Testing and Development</title>'#13#10 +
          '<link rel="stylesheet" type="text/css" href="http://www.matlus.com/home-styles.css" />'#13#10 +
          '  </head>'#13#10 +
          '<body>'#13#10 +
          '<table class="formbackground" cellpadding="2" cellspacing="2">'#13#10 +
          '<caption class="formcaption"><b>Upload File(s) along with Form fields</b><caption>'#13#10 +
          '  <tr>'#13#10 +
          '    <td class="fieldnames">Person Name</td>'#13#10 +
          '    <td><input name="txtPersonName" type="text" value="' + ContentFields.Values['txtPersonName'] + '" style="width: 200px;"></td>'#13#10 +
          '  </tr>'#13#10 +
          '  <tr>'#13#10 +
          '    <td class="fieldnames">Description of File being uploaded</td>'#13#10 +
          '    <td><input name="txtDescription" type="text" value="' + ContentFields.Values['txtDescription'] + '" style="width: 200px;"></td>'#13#10 +
          '  </tr>'#13#10 +
          '  <tr>'#13#10 +
          '    <td class="fieldnames">Name of File Uploaded</td>'#13#10 +
          '    <td><input name="txtDescription" type="text" value="' + Files[0].FileName + '" style="width: 300px;"></td>'#13#10 +
          '  </tr>'#13#10;
      end;
        { For each file that was uploaded, create a link }
        for i := 0 to Files.Count -1 do
          Response.Content := Response.Content +
            '  <tr>'#13#10 +
            '    <td class="fieldnames">Click Here to download the file</td>'#13#10 +
            '    <td><a class="fieldlink" href="ftp://' + Request.Host + '/Upload/' + Files[i].FileName + '">Download File</a></td>'#13#10 +
            '  </tr>'#13#10;

        Response.Content := Response.Content +
        '</table>'#13#10 +
        '</body>' + #13#10 +
        '</html>'#13#10;
    finally
      Free;
    end;
  end; { with TMsMultipartFormParser.Create do }
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -