Note: questions of this nature you might want to send to [EMAIL PROTECTED] as that is a list specifically about cgi, though in most cases the beginners list will be able to help you too.
Vargas Media wrote: > Hi, > I have been studying with the O'Reilly book "CGI Programming with Perl" - > Chapter 5 page 99 > Below is an example of a upload.cgi that utilizes CGI.pm > I am not able to get it to work correctly yet and I am trying to find out if > it is the directory I am trying to load the file to or a progammatical > error. The html is at: > http://www.vargasmedia.com/upload.htm > I have been using > http://www.vargasmedia.com/cgi-bin/env_var.cgi > to help me get the information I need to upload files using the correct > path. > Is that a good way to go about it and if so what Environment Variable should > I be looking at to return a path I can use... > DOCUMENT_ROOT I don't quite understand what you are asking here? Can you be more specific?? > I have an empty folder on my server under www that is called "uploads" and > wanted to upload files there. > Here is the code from the Book "CGI Programming with Perl - it is in Chapter > 5 - page 99 Is this the code you are using, in env_var.cgi?? > -PS:btw- What is the CHMOD setting that I should be using with this CGI and > "uploads" directory? two things need to be addressed here, both the ownership and the permissions, and they are related. The web server runs as a particular user, example the "apache" user on some systems with apache, and that user has its own group, example "httpd" on some systems (many others are nobody/nobody, etc.). The user who is "writing" the file to the disk (aka the web server user) must have write permission to the folder this is usually either accomplished by setting the ownership of the directory to the user and then providing the user write ability, or setting the group of the directory to one of the groups that the web server runs as and then setting group writeable permissions on that directory. If you are on unix consult -> man chown and -> man chmod for more about these two topics, on windows I can't help you sorry. A cursory (read: 30 second) look over your code didn't show any glaring problems. Is there an error given? What shows up in the error log for the web server and/or what is printed to the browser? More specific info might better help us diagnose the problems you are having. I attempted to upload a file and got a 500 error which could be a lot of things but should produce an error output in the error log. http://danconia.org > Forgive me I'm new :) > Any help extremely appreciated. > Steve > ############################################################################ > ######### > #!/usr/bin/perl -wT > > use strict; > use CGI; > use Fcntl qw( :DEFAULT :flock ); > > # use constant UPLOAD_DIR => "/usr/local/bin"; > use constant UPLOAD_DIR => " /www/vargasmedia/uploads/"; > use constant BUFFER_SIZE =>16_384; > use constant MAX_FILE_SIZE => 100 * 1_048_576; > use constant MAX_DIR_SIZE => 100 * 1_048_576; > use constant MAX_OPEN_TRIES =>100; > > $CGI::DISABLE_UPLOADS = 0; > $CGI::POST_MAX = MAX_FILE_SIZE; > > my $q = new CGI; > $q->cgi_error and error( $q, "Error transferring file: ". $q->cgi_error ); > > my $file = $q->param( "file" ) || error( $q, "No file > recieved." ); > my $filename = $q->param( "filename" ) || error( $q, "No filename > entered." ); > my $fh = $q->upload( $file ); > my $buffer = ""; > > if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) { > error( $q, "Upload directory is full." ); > } > > # Convert odd ball characters to underscore > $filename =~ s/[^\w.-]/_/g; > if ( $filename =~ /^(\w[\w.-]*)/ ) { > $filename = $1; > } > else { > error( $q, "Invalid file name; files must start with a letter or > number." ); > } > > # open output file, making sure the file name is unique > until ( sysopen OUTPUT, UPLOAD_DIR . $filename, O_CREAT | O_EXCL ) { > $filename =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e; > $1 >= MAX_OPEN_TRIES and error( $q, "Unable to save your file." ); > } > # This is neccessary for non-Unix systems does nothing on UNIX > binmode $fh; > binmode OUTPUT; > > # write contents to output file > while ( read($fh, $buffer, BUFFER_SIZE ) ) { > print OUTPUT $buffer; > } > > close OUTPUT; > > sub dir_size { > my $dir = shift; > my $dir_size = 0; > > > # loop through files and sume the sizes; doesn't decend down subdirs > opendir DIR, $dir or die "Unable to open $dir: $!"; > while ( readdir DIR ) { > $dir_size += -s "$dir/$_"; > } > return $dir_size; > } > > sub error { > my( $q, $reason ) = @_; > > print $q->header( "text/html" ), > $q->start_html( "Error" ), > $q->h1( "Error" ), > $q->p( "Your upload was not processed because the following error", > "occured: "), > $q->p( $q->i( $reason )), > $q->end_html; > exit; > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]