Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading a file from a local desktop to a Unix server

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
I'm attempting to create a simple script that takes a user defined file from their local desktop and post the file to the remote server.

first off I would need this -

<INPUT type=file size=30 name=file> to open a dialog box and the user can load the file in.

next...What should I do? <form post>???

Can I do a ftp system command to send and mv the file into the right directory? What would be the simplest?

Thanks
 
There is a thread in this forum a few days back that deals with some issues on uploading......

Here is a simple example using CGI.pm...

[tt]
#!/usr/local/bin/perl
# author:
# date: june 8,2000
# Purpose: figure out how to use CGI.pm to upload file via
# the browser.
##############################################################
use CGI;
$thisCGI = '/cgi-bin/examples/upload';

$query = new CGI;
print $query->header,$query->start_html(-title=>&quot;UPLOAD THIS&quot;);
print $query ->start_multipart_form('POST',&quot;$thisCGI&quot;);

print &quot;Enter or Browse to the file you would like to upload.<BR>\n&quot;;
print $query->filefield(-name=>'fileID',
-size=>50,
-maxlength=>80);

my $fileID = $query->param('fileID');
@pathName = split(/\\/,$fileID);
$newFile = '/some/new/path/examples/';
$newFile .= pop(@pathName);

if ($fileID)
{
open(OPF,&quot;>$newFile&quot;) || &showError(&quot;Failed to open OPF, $!&quot;);
while ($bytesread=read($fileID,$buffer,1024)) { print OPF &quot;$buffer&quot;; }
$type = $query->uploadInfo($fileID)->{'Content-Type'};
print &quot;<BR>Upload of $newFile of type $type Successful<BR>\n&quot;;
}

print '<BR>',$query->submit('doWhat','uploadMe');
print $query->end_form;
print $query->end_html;

sub showError
{
my @error = @_;
print &quot;<CENTER><font color=\&quot;\#ff4500\&quot;>Fatal ERROR - @error</font><BR>\n&quot;;
print &quot;Submission aborted - your data was not saved!!<BR>\n&quot;;
print &quot;Please use the BACK button to return to the previous page<BR>\n&quot;;
print &quot;and correct the error.<BR></CENTER>\n&quot;;
print $query->end_form,$query->end_html;
exit;
}
[/tt]

hope this helps.
 
Just out of curiousity how could I use the above script to send the uploaded file as an attachment to an email?

JK

 
Ditto - Mike's suggetsion. The CGI.pm module does not &quot;address&quot; email stuff. ;^)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top