http://www.perlmonks.org?node_id=163771


in reply to File::Copy across a Network

<kbd>$formdata{file}</kbd> ? could it be that you are disregarding the three rules of cgi-programming ?

  1. thou shalt use CGI.pm
  2. thou shalt use CGI.pm
  3. thou shalt use CGI.pm

Another point: I think you have mixed up file upload via HTTP and copying across a network. if you are using a browser to upload, you do not need to copy the file across the network from your perl script. it's already on your webserver, in a temporary file, it was transferred via HTTP.

Try this:

use CGI; use strict; my $query = new CGI; if ( $query->upload('file') ) { my ($fh,$info,$sourcefilename,$targetdir); my ($targetfilename, $type); $fh = $query->upload('file'); $info = $query->uploadInfo($fh)->{'Content-Disposition'}; $sourcefilename = "somefile.dat"; if ($info =~ m/filename="(.*?)"/) { $sourcefilename = $1; } $type = $query->uploadInfo($fh)->{'Content-Type'}; $targetdir = "\\\\Giotto\\recourse"; $targetfilename = "$targetdir\\$sourcefilename"; print "<p>The target directory for this file is: $targetdir"; print "<br>The info about this upload field was: $info"; print "<br>The original filename was : $sourcefilename"; print "<br>The type was : $type"; print "<br>This makes the target path: $targetfilename"; open(OUT, ">$targetfilename"); binmode($fh); while(<$fh>) { print OUT; } close OUT; }

On my (Win98) Machine I get the following output:

The target directory for this file is: \\Giotto\recourse
The info about this upload field was: form-data; name="file"; filename="Artistic.txt"
The original filename was : Artistic.txt
The type was : text/plain
This makes the target path: \\Giotto\recourse\Artistic.txt

--
Brigitte    'I never met a chocolate I didnt like'    Jellinek
http://www.horus.com/~bjelli/         http://perlwelt.horus.at
  • Comment on Re: File::Copy across a Network (or rather: File Upload with HTTP/CGI)
  • Download Code