How can I let a user upload a file to my site?


How can I let a user upload a file to my site?  I am running a web site on an sgi and I want people to be able to upload stuff to me.  I own the sgi so I have total access to everything.
I don't really have clue where or how to approach this.  Is there any examples of how do to this or does anyone have any simple scripts I could use to do this.  I would prefer a user to have to enter a password before they can upload something to my site.  

Thanks for any help.
Who is Participating?
undefConnect With a Mentor Commented:
#!/usr/bin/perl -w -T

$datapath = 'absolute/path/to/dir';

use CGI;

$q = new CGI;

if(not $q->param){
      print +
} else {
      $filename = $q->param('file');
      open FILE, ">$datapath/$filename"; #BIG SECURITY HOLE:)
            print FILE $buffer;
      close FILE;
      print $q->header;
      print "File: $filename uploaded\n";
onestarAuthor Commented:
Your script runs great thanks.
But what do you mean BIG SECURTIY HOLE?
How so...
Just because anyone could upload anything to my server or is there something else?  What if you made them enter a password before they could get to this page.  Or something like you have to log in before you are allowed to do this.  What do you suggest?

Also is there any limitations about file size?
Can you limit the max. size of a file the server will accept?
BSH:)  - BUG SECURITY HOLE -- means ther somebody may delete files from server... use some radom names with a file extension :

$ext = split /\./,$filename)[-1];
$name = rand (10000) . $ext;
open FILE,">$datapath/$name";

or to be sure that is correct file type use may do this:

$filename = $query->param('file');
$type = $query->uploadInfo($filename)->{'Content-Type'};
unless ($type eq 'text/html') {
          die "HTML FILES ONLY!";
$query from sample;)
use $q in your script..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.