Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

896 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

14 Experts available now in Live!

Get 1:1 Help Now