Hello

I am trying to upload a word doc and a jpg image using CGI. The problem is that the word doc says "The document name or path is not valid." And when I upload a jpg it comes out all garbled. Works fine if I use a bmp. I think I'm just missing something. Pretty new to this.

Thanks in advance!

#! C:\perl\bin\perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); my ($i, $line, $t_name, $name, $ver, $comments, $comments_new, $buffer +, $bytesread); my (@fileinput, @table_dat, @data, @fileinput_ap, @comments, @test); # Some Security Holes Plugged $CGI::POST_MAX = 100 * 1024 * 1024; # limit posts to 100M max my $q = new CGI; ######################################### # Get data from input and Untaint # ######################################### $t_name = $q->param('ap_name') or die "Cannot find name: $!"; if ( $t_name =~ /^([a-zA-Z\d_\s]+)$/ ) { $name = $1 } else { print "Content-type: text/html\n\n"; print "Only letters, numbers, underscores and whitespaces are allo +wed in the name field!!"; exit; } ################# # Upload images # ################# # Image my $file_name01 = $q->param('name_upfile01'); my $file01 = $q->upload('upfile01') or die "test:$!"; # Word doc my $file_name02 = $q->param('name_upfile02'); my $file02 = $q->upload('upfile02') or die "test:$!"; mkdir "C:/web/aps/mi/$name", 0755 or die "Cannot make dir: $!"; open (OUTFILE, ">>C:/web/aps/mi/$name/$file_name01") or die "Cannot op +en dir $name: $!"; while ($bytesread=read($file01,$buffer,1024)) { print OUTFILE $buffer; } close OUTFILE; open (OUTFILE2, ">>C:/web/aps/mi/$name/$file_name02") or die "Cannot o +pen dir $name: $!"; while (<$file02>) { print OUTFILE; } close OUTFILE2;

In reply to Trouble Uploading Word Doc and JPG by bkiahg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.