Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: allowing form uploading

by true (Pilgrim)
on Oct 16, 2002 at 05:13 UTC ( #205637=note: print w/replies, xml ) Need Help??

in reply to allowing form uploading

Want to parse your very own attachment uploads without
using a module? That's what you were asking.
Simpliest way i've used without a module is called ''
It's a downloadable perl script you include in your perl
script and can run on your webserver just fine.

I didn't get too deep into your code. I'd rather submit
some helpful pointers which may guide you on your way.

Basically you want perl to receive the form inputs from an
html page on a visitor's computer. Two areas need
setting up to do this by yourself with no module:
1. html form needs an enctype modifier.
Without this, your browser sends the
contents of your form as a simple buffer.
Make sure you have the following
included in your html form tag code:
<form method=post enctype='multipart/form-data'>
Now that you did that, you need to read what
was received in perl. There are a ton of helpful
modules which will do this for you 1000 times better than
little ole me could convey, but you said virtual host,
without a module. Again, i remind you of, see above.
Tinkering with multi-type forms isn't an entire waste of
time. You start to see how MIME works
which can be handy for custom email readers.

To start, take a look at what perl is sending you.
Self-testing is the best learning tool here.
In particular take a look at your ENV variables
when you upload a file to your test script.
In particular, look at $ENV{'CONTENT_TYPE'}.
$ENV{'CONTENT_TYPE'} has a boundary modifier, parse this.
You will use the boundary to delimit the remainder of your
form. Once you know the delimiter you can split your
uploaded content into it's seperate parts and begin to hack away.
Each part has a HEAD and a BODY. The head tells
you the filename, and describes the content.
The BODY is the content (i.e. your image, or file)
described by the HEAD.
The HEAD and BODY are seperated by \n\n
#Print your ENV variables so you can find your boundary foreach $key(keys %ENV){ print "$key...$ENV{$key}\n"; }

Replies are listed 'Best First'.
Re: Re: allowing form uploading
by George_Sherston (Vicar) on Oct 16, 2002 at 12:54 UTC
    It pained me to -- such a helpful (in spirit at any rate) node, but
    (A) in general I think it's a bad idea to encourage use of instead of for all kinds of reasons including code re-use and long term optimisation for developer time;
    (B) I don't like solutions that aim to avoid using modules - mostly because I myself got burned by lazily pursuing such solutions, so I have the zeal of the reformed;
    (C) Even if, which I don't believe, there was a good reason for resisting *new* modules in the script, sulfericacid is already using, and it's super-perverse to *replace* it with cgi-lib.

    George Sherston

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://205637]
and a moth chases the moon...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-05-27 18:06 GMT
Find Nodes?
    Voting Booth?