Gossamer Forum
Home : General : Perl Programming :

File Upload Script.

(Page 1 of 2)
> >
Quote Reply
File Upload Script.
I found this script on the web:

Quote:
#!/usr/bin/perl -w

use CGI;

$upload_dir = "/";

$query = new CGI;

$filename = $query->param("photo"); $email_address = $query->param("email_address"); $filename =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = $query->upload("photo");

open UPLOADFILE, ">$upload_dir/$filename";

while ( <$upload_filehandle> ) { print UPLOADFILE; }

close UPLOADFILE;

print $query->header ( );

print "Content-type: text/html\n\n";

print qq|

<HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD>

<BODY>

<P>Thanks for uploading your photo!</P> <P>Your email address: $email_address</P> <P>Your photo:</P> <img src="/$filename" border="0">

</BODY> </HTML>

|;


that is running here:

http://server5.hypermart.net/...ileupload/upload.htm

This error in the hypermart log is:

Undefined subroutine CGI::upload

How can this be fixed?


---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------

Last edited by:

Philip_Clark: Oct 17, 2001, 12:34 AM
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Is that the whole script?

Last edited by:

AndyNewby: Oct 17, 2001, 7:43 AM
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
You've printed the header twice too...

print $query->header ( );
print "Content-type: text/html\n\n";

Last edited by:

RedRum: Oct 17, 2001, 7:50 AM
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Also make sure you have an up to date version of CGI.pm installed and also MIME::Lite is installed.
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Hypermart servers are missing the CGI::upload module.

Ask them to install it (hmm, not likely), or move to different host.

- wil
Quote Reply
Re: [Wil] File Upload Script. In reply to
Quote:
Hypermart servers are missing the CGI::upload module.

I'm guessing it is actually done on purpose...although it is pointless as there are other ways to upload files :)
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
The upload() function was only added to CGI.pm version 2.47, which is the very latest version.

I suggest you either ask Hypermart to upgrade their current version of CGI.pm or even Perl in general!!!

For now, however, you will have to use an older method:
Code:
open (OUTFILE,">>/path/to/file");
while ($bytesread=read($filename,$buffer,1024)) {
print OUTFILE $buffer;
}
close $filename;
Cheers

Wil

- wil
Quote Reply
Re: [Wil] File Upload Script. In reply to
Of course you don't want

close $filename;

Tongue
Quote Reply
Re: [Wil] File Upload Script. In reply to
Lol....If you ask me, find a decent host Crazy Hypermart are crap! The dont let you run most scripts cos they dont have bits installed, and every page you go on brings up 1 small banners, and 1 full banner Frown

I gave up with em about 2 years ago...lol

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] File Upload Script. In reply to
You get what you pay for .....or...mmm don't pay for in some cases.
Quote Reply
Re: [RedRum] File Upload Script. In reply to
Yup, thats why I prefer to pay a few $'s and get a decent service Cool

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] File Upload Script. In reply to
Yeah, I was with them when they first started, before being aquired by goto.net. Wonderful, personal service back then.

Now, ugh, stay well away!

- wil
Quote Reply
Re: [Wil] File Upload Script. In reply to
It doesn't produce an error anymore but it doesn't upload the file Frown

Quote:
#!/usr/local/bin/perl -w
use CGI;
$upload_dir = "/";
$query = new CGI;
$filename = $query->param("photo");
$email_address = $query->param("email_address");
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("photo");
open (OUTFILE,">> /home/fileupload");
while ($bytesread=read($filename,$buffer,1024)) {
print OUTFILE $buffer; }
print $query->header ( );
print qq|
<HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD>
<BODY>
<P>Thanks for uploading your photo!</P> <P>Your email address: $email_address</P> <P>Your photo:</P> <img src="$filename" border="0">
</BODY> </HTML>
|;

Any ideas why guys?

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------

Last edited by:

Philip_Clark: Oct 17, 2001, 1:12 PM
Quote Reply
Re: [RedRum] File Upload Script. In reply to
Quote:
I'm guessing it is actually done on purpose...although it is pointless as there are other ways to upload files :)

Is there an easier way Paul?


---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
That should still give an error as you didn't remove upload("photo");
You also don't seem to be opening a file >>/home/fileupload

Anyway....try:

Code:
#!/usr/local/bin/perl -w

use CGI qw(:standard);

my $q = new CGI;

my $filename = $q->param("photo");
my $f = $filename;

my $email_address = $q->param("email_address");

$filename =~ s/.*[\/\\](.*)/$1/;

open (OUTFILE,">/path/to/upload/$filename") || die $!;
while ($bytesread=read($f,$buffer,1024)) {
print OUTFILE $buffer;
}
close OUTFILE;

print $q->header();
print qq|
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo!</P>
<P>Your email address: $email_address</P>
<P>Your photo:</P> <img src="$filename" border="0">
</BODY> </HTML>
|;

Last edited by:

RedRum: Oct 17, 2001, 1:26 PM
Quote Reply
Re: [RedRum] File Upload Script. In reply to
Thanks a lot Paul Smile. I'll give it a try and let you know.

Oh no it looks as though Man Utd are going down. ShockedFrown

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------

Last edited by:

Philip_Clark: Oct 17, 2001, 1:26 PM
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Haha - Im watching it as we speak............ohhhh cole you fool!
Quote Reply
Re: [RedRum] File Upload Script. In reply to
I know!! Why did it have to fall to Cole!

Just not their day Unsure

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [RedRum] File Upload Script. In reply to
3 minutes Injury time - COME ON!

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Ah well...good job Im a City fan...haha.....just thought I'd fuel the flames :)
Quote Reply
Re: [RedRum] File Upload Script. In reply to
I get these errors Paul: Frown


Name "main::upload_filehandle" used only once: possible typo at /home/fileupload/upload.cgi line 8.

Name "main::bytesread" used only once: possible typo at /home/fileupload/upload.cgi line 10.

Name "main::upload_dir" used only once: possible typo at /home/fileupload/upload.cgi line 3.
Undefined subroutine CGI::upload


Code:
#!/usr/local/bin/perl -w

use CGI qw(:standard);

my $q = new CGI;



my $filename = $q->param("photo");

my $f = $filename;

my $email_address = $q->param("email_address");

$filename =~ s/.*[\/\\](.*)/$1/;

open (OUTFILE,">/fileupload/$filename") || die $!;

while ($bytesread=read($f,$buffer,1024)) {

print OUTFILE $buffer;

}

close OUTFILE;

print $q->header();

print qq|

<HTML>

<HEAD>

<TITLE>Thanks!</TITLE>

</HEAD>

<BODY>

<P>Thanks for uploading your photo!</P>

<P>Your email address: $email_address</P>

<P>Your photo:</P> <img src="$filename" border="0">

</BODY> </HTML>

|;

http://server5.hypermart.net/...ileupload/upload.htm

Any ideas Paul?

Thanks for your help by the way - I really appreciate it Smile

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------

Last edited by:

Philip_Clark: Oct 17, 2001, 1:46 PM
Quote Reply
Re: [RedRum] File Upload Script. In reply to
Well I'm a West Ham fan. Damn we've been having a poor season Unsure

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Are you sure you updated the code properly?

The code I gave doesnt use upload_dir or upload_filehandle

Is that the full script?
Quote Reply
Re: [RedRum] File Upload Script. In reply to
I get these errors now:


Undefined subroutine CGI::upload

Name "main::bytesread" used only once: possible typo at /home/fileupload/upload.cgi line 9.

No such file or directory at /home/fileupload/upload.cgi line 8.



Screenshot: http://server5.hypermart.net/...ileupload/screen.jpg

Yes that's the full script.

Code:

Quote:
#!/usr/local/bin/perl -w
use CGI qw(:standard);
my $q = new CGI;
my $filename = $q->param("photo");
my $f = $filename;
my $email_address = $q->param("email_address");
$filename =~ s/.*[\/\\](.*)/$1/;
open (OUTFILE,">/fileupload/$filename") || die $!;
while ($bytesread=read($f,$buffer,1024)) {
print OUTFILE $buffer;
}
close OUTFILE;
print $q->header();
print qq|
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo!</P>
<P>Your email address: $email_address</P>
<P>Your photo:</P> <img src="$filename" border="0">
</BODY> </HTML>
|;

and

Quote:
<html>
<FORM ACTION="upload.cgi" METHOD="post" ENCTYPE="multipart/form-data">
Photo to Upload: <INPUT TYPE="file" NAME="photo"><br><br>
Your Email Address: <INPUT TYPE="text" NAME="email_address"><br><br>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form">
</FORM>
</html>



---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------

Last edited by:

Philip_Clark: Oct 17, 2001, 2:49 PM
Quote Reply
Re: [RedRum] File Upload Script. In reply to
By the way should this work with version 2.74 of CGI.pm and MIME:Lite installed?

Quote:
#!/usr/bin/perl -w

use CGI;

$upload_dir = "/";

$query = new CGI;

$filename = $query->param("photo"); $email_address = $query->param("email_address"); $filename =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = $query->upload("photo");

open UPLOADFILE, ">$upload_dir/$filename";

while ( <$upload_filehandle> ) { print UPLOADFILE; }

close UPLOADFILE;

print $query->header ( );

print "Content-type: text/html\n\n";

print qq|

<HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD>

<BODY>

<P>Thanks for uploading your photo!</P> <P>Your email address: $email_address</P> <P>Your photo:</P> <img src="/$filename" border="0">

</BODY> </HTML>

|;

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
> >