I have written a script to upload files to a site hosted by our company.
The upload subroutine is just part of a bigger project. Everything in the
project works except for the uploading subroutine. Can some one help me
figure out what I'm doing wrong? Here is an html code and the subroutine
isolated. I'm running  Webstar on a MacOS server with MacPerl.

Note the script  runs fine when I run it on the server, but when
I run it of another computer on the network or remote it fails. Here is the code.
I have removed my server name and placed the word "server"...

-- PONCE

HTML file: Named "upload.html"
-------------------------------------------------------------------
<html><head><title>Uploading Files</title>
</head><body>
<form method="post" action="http://server/cgi-bin/upload.cgi";
name="form"></center>
<!-- <form action="http://server/cgi-bin/upload.cgi"; method="post"
enctype="multipart/form-data"> -->

What file would you like to upload?
<input type="file" name="uploadfile" size="30">
<input type="submit">

</form></body></html>
-------------------------------------------------------------------

CGI Script: Named "upload.cgi"
-------------------------------------------------------------------
#! perl -w
use strict;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";
print '<HTML><Head><Title>Upload Damn It</title></head><body
bgcolor="#FFFFFF">';

my ($file) = param ('uploadfile');
my ($data, $length, $chunk, @newpath, @path, $filename, $filepath);

# grab the filename from filepath
 @path = split(/\//, $file);
 $filename = pop(@path);

# replacing path to MacOS path
@newpath = split(/\//, $file);
shift(@newpath);
$filepath = join(":", @newpath);

# debugger
#print 'filename = '; print "$filename";
#print '<p>OldPath = '; print "$file";
#print '<p>NewPath = '; print "$filepath" || die ("Error message: $!");
#exit;

 open (FILE, "$filepath") || Error2 ();

if ($filename) {
 open (UPLOAD, ">:tmp:$filename") || Error1 ();
 while (read FILE, $data, 1024) { print UPLOAD $data;}
 close (UPLOAD);
 close (FILE);
 print "<p>You uploaded <b>$filename</b>.";
 print '</body></HTML>';
 exit;
 }

else {
 print "No file was chosen.";
 }

sub Error1 {
 print "Couldn't open temporary file: $!";
 exit;
 }

sub Error2 {
 print "Couldn't open input file: $!";
 exit;
 }
-------------------------------------------------------------------


Reply via email to