Advertisement
Guest User

Gallery appmod

a guest
Jul 4th, 2010
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.00 KB | None | 0 0
  1. -module(gallery).
  2.  
  3. -export([out/1]).
  4.  
  5. -include("/usr/lib/yaws/include/yaws_api.hrl").
  6.  
  7. out(A=#arg{req=#http_request{method='GET'}}) ->
  8.     case A#arg.appmoddata of
  9.     undefined ->
  10.         {ehtml, [{h1, [], "Upload form"},
  11.              {form, [{method, "post"},
  12.                  {enctype, "multipart/form-data"}],
  13.               [{input, [{type, "file"},
  14.                 {name, "file"}]},
  15.                {input, [{type, "submit"},
  16.                 {value, "Upload"}]}]}
  17.             ]};
  18.     Other ->
  19.         {ehtml, [{h1, [], "Appmod path"},
  20.              {p, [], ["Path: ", Other]}
  21.             ]}
  22.     end;
  23.  
  24. out(A=#arg{req=#http_request{method='POST'}}) ->
  25.     MultipartOpts = [no_temp_file],
  26.     case yaws_multipart:read_multipart_form(A, MultipartOpts) of
  27.     {done, Params} ->
  28.         [{filename, Filename}, {value, Contents}] = dict:find("file", Params),
  29.         {ehtml, [{h1, [], "File received"},
  30.              {p, [], ["Received ", Filename]}
  31.             ]};
  32.     {error, Reason} ->
  33.         {ehtml, [{h1, [], "Error"},
  34.              {p, [], ["Reason: ", Reason]}
  35.             ]};
  36.     Other ->
  37.         Other
  38.     end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement