Solved

attachment fo files by end-user on the net through my form

Posted on 1998-08-27
2
191 Views
Last Modified: 2013-12-25
I want to give the facility of file attachment in a form that can be filled up by end-user on my personal page on the net.
Is there a way to send a zip/ascii/binary file to a specified email address. I want to use a form where you can write
    your eamail adress down and get the specified  file format emailed to you.
Can Filemail.pl file help me to solve my problem. which is available at http://gladstone.uoregon.edu/~mwheeler/cgi

In this script I'm not sure about the one variable which is:

      $filebase = '/home/web/draco/www/download';
    # The base path to all files you want sent. If the files are coming from
    # multiple directories you must show this in the filename part of the
    # form such as chat/chat.cgi. If you use the archiving feature all files in
    # this directory (and only this directory) will be listed.

If end-user/client is attaching the file from his hard disk (from C: or A: or D: drive). in that case what will be path for $filebase variable.

One more question:
The html file from where teh end-user will fill up the form. The input tag for giving file attachment facility will be: <input type="file" name="filename">        ?
If not then what?

Waiting for your kind and humble response.

Thanks & Regards
Ritu
0
Comment
Question by:gritu
2 Comments
 
LVL 1

Expert Comment

by:stormerider
ID: 1828331
Something tells me this is worth more than 10 points.. =) I know that uploading a file is done via INPUT TYPE=FILE, but the name is not the filename, it's the name of the variable which will be passed to the CGI script. The contents of that variable, will, I believe, be the file. Something I haven't done yet, but have read about.
0
 
LVL 5

Accepted Solution

by:
thoellri earned 10 total points
ID: 1828332
Yuck - don't even start to muck around with Perl and CGI without using CGI.pm!!!! Go to your next CPAN site and download the latest CGI.pm (version 2.42). Read the installation instructions and install it on your site.
I've just recently implemented the File-Upload option in one of my web-servers and it works like a charm. Here is a small snipplet (sample script that comes with CGI.pm) which shows you how to handle things:

.
# Start a multipart form.
print start_multipart_form(),
    "Enter the file to process:",
    filefield('filename','',45),
    br,
    checkbox_group('count',\@types,\@types),
    p,
    reset,submit('submit','Process File'),
    endform;

# Process the form if there is a file name entered
if ($file = param('filename')) {
    $tmpfile=tmpFileName($file);
    $mimetype = uploadInfo($file)->{'Content-Type'} || '';
    print hr(),
          h2($file),
          h3($tmpfile),
          h4("MIME Type:",em($mimetype));

    my($lines,$words,$characters,@words) = (0,0,0,0);
    while (<$file>) {
        $lines++;
        $words += @words=split(/\s+/);
        $characters += length($_);
    }
    close $file;
.

CGI.pm is nice enough to give you filehandle associated with the file-upload field. You can see that we directly "read()" from the CGI-file-upload-field-parameter. Very nice, robust and easy.

Also consider using available Perl-Modules to do the sending for you. If you send multiple file-types, then consider making them multipart-MIME-messages.

Go to http://www.cpan.org/modules/by-module/CGI  for the CGI.pm module
Go to http://www.perl.com/CPAN-local/modules/by-module/MIME/ for MIME-Lite

Hope this helps
  Tobias

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now