in reply to Upload a file from home dir

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:

#!/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!'); }
Make sure that the script has permission to write to $output_file.

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

Replies are listed 'Best First'.
Re2: Upload a file and format txt
by MonkPaul (Friar) on Apr 01, 2005 at 15:10 UTC
    Ah, i see... thanks for the hint on txt formatting. Theres me rushing into things again. You learn something new everyday. I hope this is more readable. Thanks for your example.
    MonkPaul.
    sub checkFile() { # print("The path name was: $file"); print("Opening File..."); print("File is now open"); @file = <FILE>; print("<BR><BR> @file<BR><BR>"); while($line = <FILE>) { chomp($line); if($line =~ /([^ACGTacgt])/) {next;} else { @cols = split(/\s/, $line); print("@cols"); } print("File is now closed"); } }