Click to See Complete Forum and Search --> : Upload file from user's computer to server


Ultimater
04-06-2005, 08:07 PM
Hey, I'm trying to make a PERL program that can accept a QUERY_STRING
containing the Location of a file chosen on the user's computer and upload the file from the user's computer to my server.
On the client-side part,
the user selects a file that they wish to upload via INPUT TYPE="FILE" and they press the submit button.

Let's say that I send the PERL program a QUERY_STRING in the format of
file=C:/myPicture.jpg

How can I look on the user's computer and upload it to the server?

Jeff Mott
04-07-2005, 12:39 AM
You don't search the user's computer. The file data is included in the HTTP request that is sent to your Perl program. You can (and should) use the CGI module to parse and handle the data. Read the CGI documentation, in particular the section regarding upload fields.

http://search.cpan.org/~lds/CGI.pm-3.07/CGI.pm#CREATING_A_FILE_UPLOAD_FIELD

Ultimater
04-07-2005, 01:14 AM
Thanks for the link Jeff Mott! Until I buy or rent a domain, I won't be able to use any modules. Tripod.com doesn't provide you with any modules and they even limit your abilites with PERL!...
So is there to do this w/o any modules?

Jeff Mott
04-07-2005, 01:22 AM
The CGI module is part of Perl's standard distribution. If you have Perl then you should have the CGI module as well. If for some reason tripod does not provide access to it then you can simply download it and package it (the CGI.pm file) with your script. This module is nothing more than a pure Perl text source file and is completely portable.

Ultimater
04-07-2005, 02:27 AM
I've tried uploading modules to tripod before,
but tripod doesn't get along with them because tripod limits your abilites in certain areas.
So is there a way to do this w/o use of a module?

Nedals
04-07-2005, 02:54 AM
Ultimater,
As Jeff mentioned, the CGI module is part of the Perl distribution and does not need to be installed.
Try this little script to check for the CGI module

NOTE: make sure the first line is correct for you

#!/usr/bin/perl

use strict;
use CGI;
use CGI::Carp(qw/fatalsToBrowser/);
my $q = new CGI;

my $message = $q->param('message');
print $q->header();
print "$message";
exit;


Call this script with
..../cgi-bin/scriptname.cgi?message=Welcome

And it should print 'Welcome' in the browser.

Ultimater
04-07-2005, 06:32 PM
When I start a new script at tripod, the first line in tripod always starts with: #!/usr/local/bin/perl
(it's set automaticly as a default text when you start writting a new program)
I used their default comment instead of yours and guess what I recieved:

Your script produced this error:
Can't locate strict.pm in @INC (@INC contains: . / /lib /site_perl) at bebebebebebeb.pl line 3.
BEGIN failed--compilation aborted at bebebebebebeb.pl line 3.


Tripod is a free website provider and doesn't contain any built-in modules...
I've also uploaded all of the modules from a CD that came with my PERL book to tripod and they didn't like my modules...
The reason is becase some of the modules use statements that were set disabled by tripod on purpose to limit your abilites...

So is there a way to do this w/o a module?

Jeff Mott
04-07-2005, 07:06 PM
Try just uploaded the few modules that your script will actually use. Most are, after all, just pure Perl that should work just as the final script itself. If that doesn't work then basically you're just stuck on a server that doesn't support Perl/CGI very well at all. Find a different server or simply test the scripts on your own machine.

Nedals
04-07-2005, 08:07 PM
Go to CPAN: http://search.cpan.org/modlist/World_Wide_Web and search for 'strict' in 'modules'

Download the 'source'
Upload that to your server in a directory called, for example, 'modules' which should be placed above your webroot directory.

Now start your script with...

#!/usr/local/bin/perl

use lib "/usr/local/apache/..../modules/"; ## or something similar which is the full path to the 'modules' directory
use strict;

If that works, do the same for the CGI.pm module.

Ultimater
04-08-2005, 12:15 AM
I downloaded the module strict and uploaded it to tripod.
The main level is ultimiacian.tripod.com
Then there is the cgi-bin folder inside of the main level.
Then I made a folder in that folder and called it modules
Then I uploaded the file strict.pm to the modules folders.
I edited my PERL program and ran it from
ultimiacian.tripod.com/cgi-bin/bebebebebebeb.pl
And guess what? It couldn't locate the lib module...
I downloaded that too and uploaded it to the modules directory.
Then I ran the Program again... still couldn't locate the module....
So I changed the program to:

#!/usr/local/bin/perl
require "modules/lib.pm";
require "modules/strict.pm";

Now I recieve an error that it cannot locate the module vars.
So I downloaded that from "your" site and uploaded that to tripod in the same directory as the last 2.
And guess what, it still can't locate the vars module....

Nedals
04-08-2005, 01:31 AM
This is not working :(
Let's start from square 1.
Do you have a free account or the 'plus' account at Tripod?
The free account does not appear to offer CGI/Perl.

Do you have any working CGI script?

Ultimater
04-08-2005, 01:34 AM
I'm using a free account at Tripod. I do have working PERL programs on the site.
Thus, Tripod supports PERL and CGI to some extent.

Ultimater
04-08-2005, 01:41 AM
It's not working because my modules and my PERL program aren't in the same folder.
I've successfully used custom-bulit modules before, but the modules had to be in the same folder.
I don't want to move all my PERL programs to the modules folder or edit each of the Modules to refer to all of the correct minor modules...
Is my header thingy being ignored totally?
What I'm asking is the statment #!/usr/local/bin/perl
refering to a folder called perl where my modules
are supposed to be stashed?
How would I change it to refer to my modules folder?
i.e. ultimiacian.tripod.com/cgi-bin/modules

Nedals
04-08-2005, 02:15 AM
#!/usr/local/bin/perl
That's the path to the Perl Interpreter. (perl is the Interpreter program, not a directory)

The STANDARD Perl Modules are generally stored in a /lib directory, which you will not have access to, and will be listed in the @INC array
Remember this?
(@INC contains: . / /lib /site_perl) (which seems to indicate that no modules are installed)

The line: use lib "/usr/../../../modules/";
is generally used to define a directory where you can install your own modules.

Thus, Tripod supports PERL and CGI to some extent.
and maybe that's the problem!

Ultimater
04-08-2005, 02:42 AM
I don't know about that....
By Using your exact code and stashing the file into my module folder along with the other three modules as of now, I recieved a different error.
It located all three modules in my Folder but it now needs warnings/register.pm ....
Something tells me that I should just download all the modules at once...

Ultimater
04-08-2005, 02:54 AM
Now I made a folder in the modles folder and called it warnings.
I uploaded the module register.pm into there.
Then afterwards I recieved an error that I needed another module
I needed the module warnings.pm in the folder modules...
So I uploaded that.
Now I need the module Carp.pm ...
Is this thing supposed to be 11 MB!?

Ultimater
04-08-2005, 03:09 AM
*Sigh*
Tripod does allow me to upload many files at once via a ZIP file.
Is there a ZIP file around containing all the modules?