Solved

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

Posted on 1998-08-27
2
196 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

830 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