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!

Hello, I have an upload sc

Status
Not open for further replies.

MagicChris

Programmer
May 30, 2001
28
GB
Hello,
I have an upload script allowing files to be uploaded to my server.
I want to intergrate an existing script i have to process a form and send
details via e-mail.

The problem i am having is that the upload script parses the form's details,
this means that when it comes to the e-mailing script to parse the form
details it is trying to parse already parsed information and doesn't work.

The form page is at - The script in .txt form is here -

If someone could have a look at it and tell me what needs to be done that
would be great!
I know it's a lot to ask and may take some time, but i would be very
greatfull if someone could solve this problem for me.

Many Thanks,
Chris G.
 
pass the arguments you want to process2.
so change line 233 to something like this:
Code:
&process2($form{'email'},$form{'realname'},$form
{'Nameon'},$form{'emailon'} ,$form{'FILE'},$form
{'FILE2'},$form{'FILE3'},$form{'FileNames'});

i didn't pass the $conifg{} variables because i guess you can access them from anywhere in the script.
and then process2 sub could be something like this:

Code:
sub process2 {
	my 
($form_email,$form_realname,$form_nameon,$form_file,$form_fi
le2,$form_file3,$form_filenames) = @_;
	&oops('You did not enter a name!') unless 
($form_realname);
if ($form_email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
	$form_email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-
Z]{2,3}|[0-9]{1,3})(\]?)$/)
      	{
	&oops('You must enter a valid e-mail address.');
	}
	&sendemail($form_email, $config
{'email_address'}, "Your Video Submission", "Hello 
$form_realname\,\r\n	Thank you for uploading a video for 
MagicChris.co.uk\'s Video Section!\r\nYour Information has 
been recieved and will be processed in a couple of 
days.\r\n\r\Should you have any question, please do not 
hesitate to contact us by e-mail.\r\n\r\Many 
Thanks\,\n\rChris G.\,\nMagicChris.co.uk");
	&sendemail($config{'email_address'}, 
$form_email, "Video Submission", "Name: $form_realname on: 
$form_nameon\r\nE-mail Address: $form_email on: $form
{'emailon'}\r\nFile 1: $config{'fileaddress'}
$form_file\r\nFile 2: $config{'fileaddress'}$form_file2
\r\nFile 3: $config{'fileaddress'}$form_file3\r\nFile 
Titles: $form_filenames");
}

hope this helps.

:)
 
Thanks for your time :)

Still doesn't work...hmmm, Still keeps bringing up the error (Oops) message "You did not enter a name!".

So i guess it's still passing the wrong info to &process2.

I'm still learning perl, so i don't really know how to write solid script, just read-understand and edit scripts.

I've zipped up all the files i've used, incase anyone wants to play around with it themselves -
Thanks,
Chris G.
 
oops...i missunderstood some of your code :)
ok. line 233 should be:
Code:
&process2($req->param('email'),$req->param('realname'),$req->param('Nameon'),$req->param('emailon') ,$req->param('FILE'),$req->param('FILE2'),$req->param('FILE3'),$req->param('FileNames'));

mistkaley i used the parameter $form...
let me know how it goes.

:)
 
ok, still not working...i think it is now ignoring process2 totally, tested it by adding
sub process2 {
my ($form_email,$form_realname,$form_nameon,$emailon,$form_file,$form_file2,$form_file3,$form_filenames) = @_;
print "Hello my name is $form_realname";
&oops('You did not enter a name!') unless ($form_realname);

So it would print something to the resulting page - but nothing.

This is a difficult one...:S

Thanks,
Chris G.
 
Breakthrough - Actually got it to send data in an e-mail and upload, wahooo!
The only thing is the data in the e-mail seems a bit wrong, will have to play around with that. Anyway, here's what i did.
Following from line 233:

use CGI;
$Data ||= $ENV{'DOCUMENT_ROOT'};
my $req = new CGI;

&process2($req->param("email"),$req->param("realname"),$req->param("Nameon"),$req->param("emailon"),$req->param("FILE"),$req->param("FILE2"),$req->param("FILE3"),$req->param("FileNames"));
}
}

And that was it,
Gonna play with it and sort out the e-mail data.
Will add to this thread when that's done.

Cheers,
Chris G.
 
Ok - script .txt updated to -
All the changes are in the sub process2.

Problem - E-mail comes out like this:

Name: Chris G. on: ON
E-mail Address: magicchris@ntlworld.com on: ON
File 1:
File 2: File 3: File Titles:
form_filenames

Instead of:

Name: Chris G. on: ON
E-mail Address: magicchris@ntlworld.com on: ON
File 1: File 2: File 3: File Titles:
Please state the trick's title of each file here.
File 1: PSupload
File 2:
File 3:


Any ideas?

Thanks
Chris G.
 
i'm doing so many things at once that i didn't notice this but...
first, take out the my $req = new CGI; out of the for loop on line 163. i didn't notice that you've put that inside the loop. big mistake :) you only need to call this once at the begining of the script, or where you want to start reading the query data.

scond, the link you've posted in the last message points to a different file than the one talked about. the call to &process2 is in the old fashion. where can i see the latest script?


:)
 
If i take out the my $req = new CGI on line 163 the script doesn't actually work - this line was part of the original script, i didn't put it there.
 
okok....i'm only with you now :)
let's do everything right this time.
delete all the occurences of:
Code:
use CGI; 
my $req = new CGI;
instead put these lines at the beginning of the script,let's say line 138:
Code:
use CGI;
local $req = new CGI;
this way you can access $req from anywhere in the script and you don't have to declare it so many times. much less overhead.

now lets go to the &process2 sub (if you did the changes above should be on line 242 now).
what's going on on line 254?
my $form_filenames = form_filenames;
delete this line.
this should do the trick.
let me know :)

p.s.
you can see the code as i fixed it at:

:)
 
Cool, Thanks a lot! Works now.

The only thing i can't get to work is to display the file names in the e-mail.
I think it's because the FILE data isn't sent as a path, it's sent as a file...so it can't write $form_file as text and so leaves a blank.

....Just fiddling around with it - File: @file_did_save - works fine.

Brilliant all sorted - Thanks a lot!
 
ahhh...that's nice :)
last thing:
you can use join to format the @file_did_save array nicer.
instead of printing it directly (which is a bad habit) do this:

Code:
"Files: ", join(", ",@file_did_save);

this way the values in @file_did_save are seperated with a comma and space.

:)
 
yeah, thought about doing that, but didn't work coz i put it in the sendmail directly,doh.
Used, "my $files = join(", ",@file_did_save);"

Works a treat, thanks m8!

Chris G.
 
Hello again,
Found a problem with the script....nothin not working properly. You can still upload a file to the server even though you have not entered a correct e-mail address or name.
This is a problem because i don't want annonymously posted files.

Got any ideas,
Cheers,
Chris G.
 
as i understand you don't want files to be uploaded, unless there's a correct email and a name. so you have to put the check before anything happens.
go to

i've put a new file there. let me know if it works. and backup your old one before using this! :)

p.s.
i left the $form_filenames variable, though it's not being used, cause i thought you might use it in the future.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top