View Full Version : uploading a file with a form
Hello all, and a Happy New Year to everyone!
I have a form on my web site which works very well. It sends an email to me with comments and also a confirmation to the sender. Now I would like the sender to also append a file (a Word document in fact) to the form which will be sent to me.
Is this going to be very difficult?
Could anyone help me please?
I am using a .cgi script at the moment with Perl.
Thank you in anticipation..
spydude006
01-05-2003, 09:28 PM
hey, go to http://www.nagsri.com/codes4u
there u will see the file upload thing.. just try it,like upload something and test it, if u like it, E-mail me at codes4u@nagsri.com, i will mail you the script.[script explains everything.. how to install, how to do ..etc..] and then take the script and add it to your script, then it makes the user to enter his name or something with the file uploaded.
UnderConstruction.:: Codes4u ::. (http://www.nagsri.com/codes4u)
Hi Spydude006
Thank you for your reply.
I have checked out the linked page and all looks well. I have sent you an email.
Thanks again
See ya
Ivy
spydude006
01-05-2003, 10:47 PM
your files -- on the way
.:: Codes4u ::. (http://www.nagsri.com/codes4u)
Hey Spydude006
I didn't receive any file attachments with the email!
Could you resend please!
Thank you
Hi all
Unfortunately the file above that spydude006 kindly sent does not do exactly what I wanted.
I am looking for the form to be sent to me (via perl / cgi) along with an attachment of the sender's choice (in particular a MS Word document).
Does anyone else have any ideas please!!!!!
Or, can you actually achieve this?
toolkit
01-16-2003, 10:04 AM
Hi
It's certainly possible.
Do you have the CGI and Mime::Entity modules installed on your server? If so, send me the script you're currently using and I will see if I can amend it for you.
Hi toolkit.
I have been searching everywhere and did nfind out that it was possible. Couldn't find a script anywhere though. The only one's I could find were upload scripts - they put the attachment on to the server and that's it. I would like the script to send the attached file directly with the email to the ($support) email address. I have put the code below taht I am currently using. It is someone elses original code, but as far as I am aware, I am allowed to change/modify it so long as I leave the copyright notice in place.
Also. I need the script to be able to send .doc .gif .jpg and .zip files only.
And... Can I limit the file size please. I do not want HUGE files being sent.
And... Can this be abused. I.e. I have been reading around scripts and you can have them so that only the specific form on my domain name can use this script.
I hope that I am not asking too much!
I appreciate all your help.
Thank you for your assistance.
#!/usr/bin/perl
####################################
#Copyright 2000, Lucas Alexander
#http://www.alexanderdevelopment.net
####################################
use CGI;
$subject = "Send us your file";
$mailprog = '/usr/sbin/sendmail'; #path to sendmail on your server
print "Content-type:text/html\n\n";
$support = 'info@DOMAINNAME.com'; #support email address
&getinput;
#############
#subroutines
#############
sub getinput {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$caller = $ENV{'HTTP_REFERER'};
$sendername = $FORM{'sendername'};
$senderemail = $FORM{'senderemail'};
$comments = $FORM{'comments'};
$companyname = $FORM{'companyname'};
$sendertele = $FORM{'sendertele'};
$returnpage = $FORM{'returnpage'};
#I have added this one line below to make the first letter of the name a capital
$newsendername= ucfirst $FORM{'companyname'};
$url=$FORM{'url'};
if ($FORM{'pagename'}) {
$pagename=$FORM{'pagename'};
}
else {
$query = new CGI;
if ($query->param('pagename')) {
$pagename = $query->param('pagename');
}
else {
$pagename = $caller;
}
}
if (!$url) {
&makesubpage;
}
else {
if ($senderemail !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/) {
$errormsg="Your e-mail address is invalid.";
&badinput;
}
elsif ($sendername !~ /[A-Z]/i) {
$errormsg="You must supply your name.";
&badinput;
}
else {
&writemail;
&writemail2;
&makeanewpage;
}
}
}
sub writemail {
open (MAIL, "|$mailprog -t");
&makemail;
close(MAIL);
}
sub writemail2 {
open (MAIL, "|$mailprog -t");
&makemail2;
close(MAIL);
}
sub makesubpage {
print<<_EOP_;
<html>
<head>
<title>The html for the form page will go here</title>
<body></body>
</html>
_EOP_
}
sub makeanewpage {
print<<_E_O_P_;
<html>
<head>
<title>Code for the thank you page will be here</title>
<body></body>
</html>
_E_O_P_
}
sub makemail {
print MAIL<<_E_O_M_;
To: $support
From: $senderemail
Subject: $subject
Hey $support,
A file has been attached to this email from, page $url
THE FILE SHOULD BE ATTACHED TO THIS EMAIL
First Name: $companyname
Last Name: $sendername
Email Address: $senderemail
Telephone: $sendertele
Comments:
$comments
_E_O_M_
}
##############THIS IS AN AUTORESPONSE TO THE SENDER
sub makemail2 {
print MAIL<<_E_O_M_;
To: $senderemail
From: $support
Subject: $subject
Hey $newsendername,
THANK YOU FOR THE FILE THAT YOU SENT TO US.
Below is a transcript of the information you sent us.
Regards
**** DO NOT ATTACH THE FILE TO THIS EMAIL ****
First Name: $companyname
Last Name: $sendername
Email Address: $senderemail
Telephone: $sendertele
Comments:
$comments
_E_O_M_
}
############down to here
sub badinput {
print<<_E_O_P_;
<html>
<head>
<title>The error page html will be here</title>
<body></body>
</html>
_E_O_P_
}
$datetime = localtime ;
###################################################################################
######### Below should log all correspondance on to a text file ###################
###################################################################################
open (LOGFILE, ">> filelog.txt") ;
flock(LOGFILE, 2) ; ##### LOCK - comment for locking on a non-Unix server.
seek(LOGFILE, 0, 2) ; ##### LOCK - comment for locking on a non-Unix server.
print LOGFILE "$companyname\t$sendername\t$senderemail\t$sendertele\t$comments\t$datetime\t$url\n" ;
flock(LOGFILE, 8) ; #### LOCK - comment for locking on a non-Unix server.
close (LOGFILE) ;
toolkit
01-16-2003, 12:08 PM
Ok Ivy, I'll try and get it done in the next few days.
I take it you do have the CGI and Mime::Entity modules installed on your server? CGI is standard, but I'm not sure if Mime::Entity is especially common. It's this module that will attach the file to the email with the correct encoding.
Hi toolkit
Sorry - I forgot to answer that question - yes. As far as I am aware this module is available on the server that I use (The server I am using is a paid server with nearly everything else on it - I have emailed the admin to check). If not, I have another server that it definitely WILL be available on.
That's very kind of you.
Thank you once again.
toolkit
01-28-2003, 04:05 PM
Hi Ivy
Just wondering if you actually got that script I sent you to work?
Hi toolkit
I should have posted a reply - my apologies...
Unfortunately I was unable to get your script to work!!! And I still do not know why. When I get time, I will take a good look at it.
I was able to find another script, TFMail (http://nms-cgi.sourceforge.net/)
This does the job perfectly using a MIME:Lite module.
All is working well. - As I said to you before, I will ensure a link goes up on the links page to your site. Thank you for your help, time and your interest.
I'll PM you within a couple of weeks, once the site goes live.
toolkit
01-30-2003, 11:00 AM
Well, I'm glad you've found something that works for you :)
and I'm sorry that you couldn't get my script to work - such are the problems with different server setups :(
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.