Saturday, 10 August 2013

File Upload Module in Apache2 Linux-Mint14-KDE

File Upload Module in Apache2 Linux-Mint14-KDE

I'm a newcomer/hobbyist so go easy on me. I have searched and experimented
quite a bit before asking.
System: Linux-mint-14-KDE (based on Ubuntu 12.10)
Server: Apache2 installed via sudo apt-get install apache2
I've successfully setup the server to serve web pages on https (port 443)
I've successfully setup password protected areas with .htaccess
My final goal was to be able to allow remote users to upload files, via a
form, to a directory.
from this site: commons.apache.org/proper/commons-fileupload/
<form method="POST" enctype="multipart/form-data" action="fup.cgi">
File to upload: <input type="file" name="upfile"><br/>
Notes about the file: <input type="text" name="note"><br/>
<br/>
<input type="submit" value="Press"> to upload the file!
</form>
I added this code to index.html and the form shows up OK. When you go to
upload files, it returns: The requested URL /fup.cgi was not found on this
server.
I don't know anything about The Common Gateway Interface, so I am stuck. I
went here http://httpd.apache.org/docs/current/howto/cgi.html
The Apache2 documentation is hard for me to follow. To
/etc/apache2/sites-available I added one part about CGI
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride Authconfig
Order allow,deny
allow from all
</Directory>
Am I supposed to have a script file called fup.CGI? Doesn't apache2 have
modules to do it for you?
Also this web page has a lot of good stuff about limiting files sizes etc.
http://commons.apache.org/proper/commons-fileupload/using.html
...but what do they mean? They say this:
Handling a request in this scenario couldn't be much simpler:
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Configure a repository (to ensure a secure temp location is used)
ServletContext servletContext = this.getServletConfig().getServletContext();
File repository = (File)
servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List<FileItem> items = upload.parseRequest(request);
That's all that's needed. Really!
What is all that? What programming language is that? In what folder would
that stuff go? It seems like the apache.org always leaves a lot of
explaing out. I figured out HTTPS, permissions, passwords, etc., on other
websites because apache.org was always so unclear.
All I want to do is let users upload files and cap them at, say, 5 GB.
This may turn out to be too hard but I'll read and try whatever is
suggested.

No comments:

Post a Comment