As posted your code is almost unreadable. (When you post code to PM, put it between <code></code> tags. Better yet, become familiar with the contents of the PM site FAQ, especially Writeup Formatting Tips.) Rather than try reading through it, here's a simple file upload script:
Make sure that the script has permission to write to $output_file.#!/usr/bin/perl -T -- use strict; use warnings; use CGI qw(:standard); print header, start_html('Upload example'); print_form() unless param; print_results() if param; print end_html; sub print_form { print h2('What file do you have for me?'), start_multipart_form(), filefield(-name => 'upload', -size=>60), submit(-label => 'Do it!'), end_form; } sub print_results { my $output_file = '../whatever'; my $file = upload('upload'); print h2('Bummer!...') and return unless $file and open my $out, ">$output_file"; { my $data; print $out $data while read $file, $data, 1024; } close $out or print h2('Not all is well...') and return; print h1('Success!'); }
Update: Fixed s/param/upload/ in print_results; the original works but the revision uses the "recommended idiom" (see perldoc CGI for a discussion on this).
the lowliest monk
In reply to Re: Upload a file from home dir
by tlm
in thread Upload a file from home dir
by MonkPaul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |