Return-Path: Delivered-To: apmail-perl-embperl-archive@www.apache.org Received: (qmail 83876 invoked from network); 9 Oct 2003 01:27:59 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 9 Oct 2003 01:27:59 -0000 Received: (qmail 82404 invoked by uid 500); 9 Oct 2003 01:27:40 -0000 Delivered-To: apmail-perl-embperl-archive@perl.apache.org Received: (qmail 82392 invoked by uid 500); 9 Oct 2003 01:27:40 -0000 Mailing-List: contact embperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list embperl@perl.apache.org Received: (qmail 82376 invoked from network); 9 Oct 2003 01:27:40 -0000 Received: from unknown (HELO marvin.oriel.com.au) (203.221.181.125) by daedalus.apache.org with SMTP; 9 Oct 2003 01:27:40 -0000 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Subject: RE: Upload file Date: Thu, 9 Oct 2003 11:27:47 +1000 Message-ID: <065B6A22A2762C4F86B8961F8FEB8912456CDB@marvin.oriel.com.au> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Upload file Thread-Index: AcON+Xj6/YRYX/NPRVew7/cMVkxRPgABHi/w From: "Andrew O'Brien" To: X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Firstly Rado, there is a typo in your "open" line: a missing closing ". The only other thing I would suggest is using BINMODE. See below for an example routine. > In EplSite WorkFlow i am using this routine and works fine: >=20 > use CGI; > $query =3D new CGI; >=20 > if( $file =3D $query->param('ImageName') ) > { > @thefile =3D split(/\\/,$file); > $elements =3D @thefile; > $thedocument =3D "$$-@thefile[$elements-1]"; > $thedocument =3D~ s/\s/_/g; > if( open (OUTFILE,">$globalp->{Documents_path}/$thedocument") ) > { > binmode(OUTFILE);# Explicit binary mode > while ($bytesread=3Dread($fdat{attachthis},$buffer,32768)) > { > print OUTFILE $buffer; > } > close(OUTFILE); > } > } >=20 > I am using CGI for some manipulation on filename but you=20 > could not use it. Ouch. CGI is completely unnecessary. Evaluating $fdat{ImageName} in string context will provide the filename of the uploaded file - Embperl is using CGI internally already to give you this filehandle. An alternative version (with the usual off-the-top-of-my-head typo caveats) that uses somewhat safer variable scope: if (my $file =3D "$fdat{ImageName}") { require File::Spec; $file =3D (File::Spec->splitpath($file))[2] # just the filename, = system independently $file =3D~ s/[^\w\.]/_/g; $file =3D~ s/_+/_/g; # replace unwanted characters, somewhat aggressively. if ( open(OUTFILE, ">$some_path/$file") ) { # this should use File::Spec as well. binmode OUTFILE; my $buffer; print OUTFILE $buffer while read($fdat{ImageName}, $buffer, 32768); close OUTFILE; } } Cheers, Andrew --------------------------------------------------------------------- To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org For additional commands, e-mail: embperl-help@perl.apache.org