What, exactly, is the question? Are you looking for code to do this, an explanation of the framework for how to do this, or general ideas for the user interface?
I recently had to do something similiar. I manage (such as one does) a large database of batteries. Users need to be able to upload pictures of batteries in to the database. There is a page with a couple of fields on, where the user enters the serial number, describes the picture (intact, exploded, top view, whatever), and, most importantly, the path to the file on their local machine. This is done using a INPUT field, with a type of FILE.
When the user clicks 'Go', the file will be submitted as part of the POST data. Note that the ENCTYPE on the FORM with the INPUT button must be set to "multipart/form-data".
Let's say that your input field is named 'photofile'. The following code
my $fn = $html->param ('photofile');
my $fh = $html->upload ('photofile');
gets the filename the user wants to upload from his local drive, and a file handle to said file. You then proceed to use a loop
#
# This could get a little hairy. We don't know how big a picture
+the user i
# give us. We're going to limit him to 512K. That should cover a
+nything we
# of.
#
while ((length ($photo) <= (512 * 1024)) && read ($fh, $buffer, 102
+4))
{
$photo .= $buffer;
}
if (length ($photo) == (512 * 1024))
{
print_file ("File too big!");
return;
}
to read the data into a string. Now I perform some other processing on the file data before it's loaded into the database, but you could copy it straight to a file (I pump the image through ImageMagick to create a thumbnail, do some normalization, and limit the dimensions of the picture). You *absolutely* need to set a limit on how much data you'll accept or some weenie may try to upload a 1,000,000 x 1,000,000 x 24 bit image of Britney Spears to see how you'll handle it.
This is the basic form of what you're trying to do. If you can clarify the question some, a little more specific help can probably be provided.
--Chris
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.