Summary: describes in detail how to upload (upload) files to the server on goAhead2.5. Development Environment: Host: WindowsXP; Virtual Machine: Ubuntu9.10; Cross Compiler: arm-uclibc-gcc (arm-linux-gcc-4.3.2 can be compiled successfully )---------------
Summary: describes in detail how to upload (upload) files to the server on goAhead 2.5.
Development Environment:
Host Machine: Windows XP;
Virtual Computer: Ubuntu 9.10;
Cross Compiler:Rm-Uclibc-gcc (arm-linux-gcc-4.3.2 can be compiled smoothly)
-----------------------------------
1. Description
Recently, I debugged the web file upload function to the server. However, during debugging, the handler function always failed to obtain the file path, so I had to find many articles on the Internet, however, the principle and implementation method of front-end File Upload are mostly mentioned, but the server-side processing implementation is not provided (implemented using the C function ). In addition, due to lack of understanding about the web, it took some time to study web programs.
2. How to upload files using goAhead
In general, it is easier to implement the file upload function on the goAhead. Because there is a ready-made code available, just port it a little.
2.1 Implementation Principle
Use html form to submit File Upload requests. The core of the web server processes the file data received by the Post client (note that the post is binary data). Finally, the web server writes the received file data in binary format to the Local Storage System of the server.
2.2 front-end design
The front-end design is relatively simple, that is, to design a form, the type attribute isFile, I am adding such a form on the asptest. asp web page of wwwdemo that comes with the goAhead-2.5.
- <Html>
- Nc., 1999-2010. All Rights ReservEd.->
- <Head>
-
- <Link Rel="Stylesheet" Href="/Style/normal_ws.css" Type="TExT/css">
- <%Language=Javascript%>
- Function uploadFileSubmit ()
- {
- // Alert (document. getElementById ("document. softupDate"));
- Return;
- }
- Head>
- <Body>
- <H1>ASP/JavaScript? Test H1>
- <H2>Expanded ASP data:<% AspTest ("Peter Smith", "112 Merry Way"); %> H2>
- <P>
- <% Var z ;\
- For (Z=0; Z<5;ZZ= Z + 1 )\
- {\
- If (z<= 2 )\
- Write(Z + "isLessThan 3<Br>");\
- ELsE if (Z= 3 )\
- Write (z + "is equal to 3<Br>");\
- Else \
- Write (z + "is greater than 3<Br>");\
- }\
- %>
- P>
- <Span Style="ColOr: # 3333ff ;">
- <H1>GoForm upload file test H1>
- <Form Id="Softupdate" Action=/Goform/formUploadFileTestMethod=POST Enctype="Multipart/form-data">
- <Table>
- Select file:<Td> <Input Id="Fileupload" Type="File" Name="Fileupload" Size=60 Value=""> Td>
- <Td> <Input Id="FileuploadSuBmit" Type="Submit" Name="Update" Value="Update" OnClick="UploadFileSubmit ()"> Td>
- Table>
- Form>
-
- Span>
- Body>
- Html>
The enctype parameter is used to set the form's MIME encoding method. When uploading a file (or containing a text box at the same time), you must set its attribute to "multipart/form-data "; formUploadFileTest is a processing function defined by the web server to write the uploaded file data received by the web server to the storage system.