PDA

Bekijk de volledige versie : How to create a file upload web page


ros
28-08-2009, 10:25
This tutorial assumes you are running lighttpd with mod-cgi.

First, make sure lighttpd.conf has this setting:
#### CGI module
cgi.assign = ( ".pl" => "/bin/sh",
".cgi" => "/bin/sh",
".cgih" => ""
)


.cgih will be the type of your upload script.

Now install haserl (must be 0.9.25 or newer)

ipkg install haserl

It will be put into /opt/bin

Now here is the modified script (source (http://haserl.sourceforge.net/)) from for uploading the files.

Give this file any name, ending with ".cgih" type. I'll use "upload.cgih" in this example:


#!/opt/bin/haserl -u 2096 --upload-dir=/upload
content-type: text/html

<html><body>


<form action="<% echo -n $SCRIPT_NAME %>" method=POST enctype="multipart/form-da
ta" >
<input type=file name=uploadfile>
<input type=submit value=GO>
<br>
<% if test -n "$FORM_uploadfile"; then %>
<p>
You uploaded a file named <b><% echo -n $FORM_uploadfile_name %></b>, a
nd it was
temporarily stored on the server as <i><% echo $FORM_uploadfile %></i>.
The
file was <% cat $FORM_uploadfile | wc -c %> bytes long.</p>
<% mv $FORM_uploadfile /upload/$FORM_uploadfile_name
%>
<% else %>
You haven.t uploaded a file yet.
<% fi %>
</form>
</body></html>


-u 2096 is the maximum allowed size of file. In kB.

Once you have file saved and lighttpd restarted (if you changed lighttpd.conf file) then give it a try:

http://<your_server>/...path.../upload.cgih

The uploaded file will be placed into /upload directory. Note that this is an absolute path.