CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
uploading files

 



quist
Deleted

Nov 30, 2000, 2:27 PM

Post #1 of 5 (529 views)
uploading files Can't Post

I'm trying to upload a file; my html line is:

<INPUT type=file name=upfile>

and my CGI code is:

$userFile = param('upfile');
$userFileHdl = upload($userFile);

$inLine = <$userFileHdl>;
print $inLine;


nothing happens. any ideas?


sleuth
Enthusiast / Moderator

Nov 30, 2000, 3:35 PM

Post #2 of 5 (529 views)
Re: uploading files [In reply to] Can't Post

 
If that code is expected to work, (I'm not sure if it will) Your probably missing this in the form.

<form method="POST" action="htp://www.site.com/uploade.cgi" ENCTYPE="multipart/form-data">

I'm reffering to the

ENCTYPE="multipart/form-data"

:)

Sleuth


quist
Deleted

Dec 1, 2000, 6:41 AM

Post #3 of 5 (529 views)
Re: uploading files [In reply to] Can't Post

this is the form line I'm using; I'm not getting an error, it's just that the contents of the text file I'm uploading are not being printed out.

<FORM method=POST action="http://dev.diamondbullet.com/dean/encoder.cgi" enctype="multipart/form-data">


sleuth
Enthusiast / Moderator

Dec 1, 2000, 12:31 PM

Post #4 of 5 (529 views)
Re: uploading files [In reply to] Can't Post

 K, then it's your script,

use this one:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qw/:standard :html3/;
$upload_dir = "/blabla/uploads";
$upload = param('upload');
$name = "$upload";
$name =~ s!^.*(\\|/)!!; #capture file name
#########################################################################################
if (-e "$upload_dir/$name"){
print qq~
<br><p align="center"><font face="Verdana"
size="2" color="#000080"><b>That File
Already Exists, Please Choose Another Name
For Your File.</b></font></p>
<p align="center"><a
href="javascript:history.go(-1)"><font
color="#000080" face="Verdana" size="2"><<<b>
Back</b></font></a></p>
~;
exit;
}
if ($upload eq ""){
$stuff = "Please Enter A Valid File location";
print "$stuff";
exit;
}
##########################################################################################
my $length;
my $size;
my $file = param('upload');
$file =~ m!([^/:\\]*)$!; #capture file name
my $short_name = $1;
open (SAVE,">$upload_dir/$short_name") | | die $!;
while ($size = read($file,$data,1024)) {
print SAVE $data;
$total_size += $size;
}
close SAVE;
if ($total_size > 0) { #file was transferred
print qq~
<p align="center"><br><font face="Verdana" size="2" color="#000080"><b>Your File
Was Successfully Uploaded.</b></font>
~;
}
else {
print qq~
<br><p align="center"><font face="Verdana" size="2" color="#000080">
<b>Your File Was Not Uploaded. Please Be Sure You Entered A Valid
File Name. If You Still Have Problems Please
Contact The Seeki Tech Dept.</b></font></p>~;
}
exit;
</pre><HR></BLOCKQUOTE>

Sleuth

[This message has been edited by sleuth (edited 12-01-2000).]


Cure
User

Dec 3, 2000, 9:45 AM

Post #5 of 5 (529 views)
Re: uploading files [In reply to] Can't Post

perldoc CGI


Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives