2
0

README.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. File upload from html form, example
  2. ==========================
  3. Demonstrates how to handle the file upload (multipart) html forms with
  4. templates.
  5. Note, that the only difference between CGI/FCGI and Apache module is in the
  6. main project .lpr file and the web server (Apache) configuration.
  7. =====================
  8. 1. Compiling
  9. 1.a; with FPC
  10. 1.b; with Lazarus
  11. 2. Setup
  12. 2.a; as CGI
  13. 2.b; as Apache module
  14. 2.c; as FCGI
  15. =====================
  16. 1. Compiling:
  17. -------------
  18. We can either use FPC directly, or Lazarus to compile the CGI/FCGI/Apache
  19. module application. The main project .lpr file, as well as the Lazarus .lpi is
  20. in the cgi/fcgi/apache directories.
  21. 1.a; with FPC
  22. -------------
  23. Enter to the directory (cgi/fcgi/apache) that has the .lpr file you wish to
  24. compile, and then execute the command
  25. fpc -Fu../webmodule fileupload.lpr
  26. The -Fu parameter shows FPC where to find the web module source code. All
  27. three web applications share the same web module code.
  28. 1.b; with Lazarus
  29. -----------------
  30. It needs the WebLaz Package installed. Open the .lpi file from the chosen
  31. application directory (cgi/fcgi/apache), and then
  32. Run -> Build from the menu.
  33. 2. Setup:
  34. ---------
  35. The application needs read access to the template file(s).
  36. It is best to use full paths with the file names in the web module
  37. (webmodule.pas), because Apache will probably look relative to the / (main
  38. root) directory or main Apache directory and not relative to the application
  39. file location.
  40. ex: ModuleTemplate.FileName := '/full/path/to/templates/uploadform.html';
  41. It needs read/write access to create the file database filelist.txt
  42. ex: FileDB := '/full/path/to/templates/filelist.txt';
  43. Also, it needs an "/upfiles" directory with read/write access where the files
  44. will be uploaded to.
  45. ex: UploadDir := '/full/path/to/upfiles/';
  46. 2.a; as CGI
  47. -----------
  48. Usually it works if you put the template (uploadform.html) next to the CGI
  49. executable file in the Apache cgi-bin directory. Adjust the file path in the
  50. web module (webmodule.pas) accordingly.
  51. http://<WebServer>/<ApacheScriptAliasName>/listfiles should start the
  52. example if everything is set up properly.
  53. ex: http://127.0.0.1:8080/fileuploader/listfiles
  54. if in the Apache configuration file (ex: httpd.conf) it was set up as
  55. ScriptAlias /fileuploader "<path_to_app>/<app_name>"
  56. ex:
  57. ScriptAlias /fileuploader "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/fileupload.exe"
  58. (uploadform.html is copied next to fileupload.exe into cgi-bin, and cgi-bin
  59. has a subdirectory called "upfiles")
  60. Note: You need to change the URLs or the Apache configuration if "fileuploader"
  61. or "fileupload.exe" changes (for example on Linux it is not fileupload.exe).
  62. Also, if your server is listening on port 80 instead of 8080, you can leave
  63. the :8080 part from the calling URL:
  64. http://127.0.0.1/fileuploader/listfiles
  65. 2.b; as Apache module
  66. ---------------------
  67. Usually it works if you put the template (uploadform.html) into the Apache
  68. main directory (not the DocumentRoot, but the main Apache directory), under
  69. sub-directory "templates" or something similar. Adjust the file path in the
  70. web module (webmodule.pas) accordingly.
  71. http://<WebServer>/<ApacheLocationName>/listfiles should start the
  72. example if everything is set up properly.
  73. ex: http://127.0.0.1:8080/fileuploader/listfiles
  74. or http://127.0.0.1/fileuploader/listfiles
  75. if in httpd.conf it was set up as:
  76. LoadModule mod_fileupload "<path_to_mod>/fileupload.dll"
  77. <Location /fileuploader>
  78. SetHandler mod_fileupload
  79. Order allow,deny
  80. Allow from all
  81. </Location>
  82. Note: You need to change the URLs in the templates if "fileuploader" changes.
  83. Also, for example on Linux the module can be libfileupload.so and not
  84. fileupload.dll
  85. Note: If you recompile an apache module while the module itself is loaded into
  86. the Apache server, the compilation might fail because the file is in use
  87. (Apache modules stay in the memory). So first, you always need to stop the
  88. server before you recompile or before you copy over the new version of the
  89. newly created module.
  90. On Linux, it is enough to simply reload Apache after recompile.
  91. 2.c; as FCGI
  92. ------------
  93. Usually it works if you put the template (uploadform.html) next to the FCGI
  94. executable file. Adjust the file path in the web module (webmodule.pas)
  95. accordingly.
  96. http://<WebServer>/<ApacheScriptAliasName>/listfiles should start the example
  97. if everything is set up properly.
  98. ex: http://127.0.0.1:8080/fileuploader/func1call
  99. or http://127.0.0.1/fileuploader/func1call
  100. if in the Apache configuration file (ex: httpd.conf) it was set up as:
  101. LoadModule fastcgi_module "<path_to_mod>/mod_fastcgi-2.4.6-AP22.dll"
  102. <IfModule mod_fastcgi.c>
  103. <Directory "<path_to_fcgi_app>">
  104. Order allow,deny
  105. Allow from all
  106. </Directory>
  107. FastCgiExternalServer "<path_to_fcgi_app>/fileupload.exe" -host 127.0.0.1:2015 -idle-timeout 30 -flush
  108. ScriptAlias /fileuploader "<path_to_fcgi_app>/fileupload.exe"
  109. </IfModule>
  110. Note: You need to change the module name if needed. For example on Linux,
  111. the module is not mod_fastcgi-2.4.6-AP22.dll but mod_fastcgi.so (need to be
  112. compiled from sources found at http://www.fastcgi.com/dist/ ).
  113. The port (2015 in this example) must match the one set in the project main
  114. file (fileupload.lpr).
  115. The FCGI application must be running in order for this demo to work (external
  116. FCGI server setup). Do not forget to restart it after changes and
  117. recompilation.
  118. Also, mod_fastcgi is not the same as mod_fcgid that the Apache project is
  119. developing. The latter does not support external FCGI server apps.
  120. There are other ways than external FCGI server apps to handle the FCGI
  121. protocol and both mod_fastcgi and mod_fcgid supports that. However, external
  122. FCGI servers are the best for debugging and development, that is why the
  123. examples do it that way.