I have been running myself into a brick wall repeatedly and I am at a point were I must beg for help. I am trying to upload several images and am passing the image paths from one form to another for processing as hidden tags. I am then trying to read in the local image file and write it to the server in a name format that I choose. I am having little luck with the last portion. It runs through a foreach array that keys on the CGI param to determine if the field is of an image type. If so it will then attempt to upload the image. In each iteration it creates the file I want to populate with the users local file but it doesnt seem to want to write the data in. This is a relatively new area for me in Perl. In the past I have used FILEHANDLES and simply read and printed the file from one handle to the other. When that failed I attempted the use of syswrite thinking it was needed to specifically write non string data. That too failed here is the following routine in question, any help is appreciated:
sub publish_html { my $q = new CGI; &get_DTG; $header_name = "header.dat"; @header = ('BEGIN','XFER',$tar_file,$DESTINATIONS,'R','U','001','0 +40','NONE',$DTG,'NONE','MPU','END'); # Ignore bad extensions if good extensions is specified. undef @bad_extensions if @good_extensions; print header; print start_html(-title=>$title_tag,-bgcolor=>$bg_color,-text=>$te +xt_color); print font({-color=>'lime'},h2({-align=>CENTER},'MPU UPLOAD PROGRE +SS')),br,br; # Create DPS Header for routing if(open(OUTHEADER, "> $TEMP_DIR/$header_name") || die("Cannot Open + File $header_file for reading: $!")) { print font({-color=>'white',-size=>$content_font_size},'Creati +ng HEADER... '),br; foreach $line( @header ){ print OUTHEADER $line."\n"; print font({-color=>'white',-size=>$content_font_size},'Wri +ting... '.$line),br; } close (OUTHEADER); print font({-color=>'white',-size=>$content_font_size},'Header +file saved to... '.$TEMP_DIR."/".$header_name),br,br; } ############################################ #PERFORM FILE CHECKING AND UPLOAD IMAGES foreach $file ($q->param) { if ($file ne "" & $file =~ /image/){ $path = param($file); # PARSE AREA HTML NAME FOR IMAGE NAME PREPEND # areafile is a param that contains the area html page na +me # this is used to prepend the areaname to the image file +to # ensure all images are unique per area. $htmlfile = param('areafile'); if ($htmlfile =~ m!^(.*)\.(.*)$!) { $html_lead = $1; $html_ext = $2; } # PARSE OUT PATH FOR BUILDING PUBLISHED IMAGE NAMES if ($path =~ m!^(.*)\\(.*)$!) { $leadpath = $1; $filename = $2; if ($filename =~ m!^(.*)\.(.*)$!) { $name = $1; $file_ext = ".".$2; } } elsif ($filename =~ m!^(.*)/(.*)$!) { $name = $1; $file_ext = ".".$2; } else { $leadpath = "."; $filename = $path; } print font({-color=>'white',-size=>$content_font_size},'P +ROCESSING FILE... '.$path),br; $path =~ s/^.*(\\|\/)//; my $proceed_type = 0; if(@good_extensions) { foreach(@good_extensions) { my $ext = $_; $ext =~ s/\.//g; if($path =~ /\.$ext$/) { print font({-color=>'white',-size=>$content_fo +nt_size},'VERIFIED FILE TYPE OF... '.$path),br; $proceed_type = 1; last; } } unless($proceed_type) { push(@was_not_good_type, $path); } } elsif(@bad_extensions) { $proceed_type = 1; foreach(@bad_extensions) { my $ext = $_; $ext =~ s/\.//g; if($path =~ /\.$ext$/) { $proceed_type = 0; last; } } unless($proceed_type) { push(@was_a_bad_type, $path); } } else { $proceed_type = 1; } # WRITE IMAGE TO SERVER USING FORM FIELD NAME .EXTENSION T +O THE $TEMP_DIR # THIS PROCESS INSURES THAT NO 2 AREAS WILL HAVE THE SAME +IMAGE NAME if($proceed_type) { if(open(OUTFILE, "> $TEMP_DIR/$html_lead$file$file_e +xt") || die("Cannot Open File $TEMP_DIR/$html_lead$file$file_ext for +writing: $!")) { print font({-color=>'white',-size=>$content_font +_size},'UPLOADING... '.$path),br; if(open(READFILE, "< $path") || die("Cannot Op +en File $path for reading: $!")) { while (my $bytesread = read(READFILE, my + $buffer, 1024)) { syswrite(OUTFILE, my $buffer, 1024); } } close (INFILE); close (OUTFILE); } } if($max_size) { if((-s "$TEMP_DIR/$html_lead$file$file_ext") > ($max_s +ize * 1024)) { push(@was_too_big, $path); unlink("$TEMP_DIR/$html_lead$file$file_ext"); } } print font({-color=>'white',-size=>$content_font_size},'FI +LE SAVED TO... '.$TEMP_DIR.'/'.$html_lead.$file.$file_ext),br,br; push(@file_did_save, $path); &results; } else { push(@did_not_save, $path); } } print start_form(-action=>$SCRIPT_NAME); print center submit(-value=>'BACK TO FORM',-onclick=>'history.go(- +2)'); close_form(); print end_html; }

In reply to Uploading an image by MadPogo

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.