Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: File::Copy across a Network (or rather: File Upload with HTTP/CGI)

by bjelli (Pilgrim)
on May 03, 2002 at 11:45 UTC ( #163771=note: print w/ replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://163771]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2015-07-06 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (73 votes), past polls