• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

CGI/Perl script that includes file attachments

Can anyone help with modifications to Matt's Script Archive - formmail.pl so that I can use a "file" (browse) type field to the web form.

OR let me know of another script to do the job.

The "user's" selected file (probably a MSWORD document)would then be sent as an email attachment along with the other data fields contained in the form.


  • 2
1 Solution
gfergusAuthor Commented:
Hi Bob

Had some problem with the html/script. The html worked ok but the brower reported 'Internal server error 500' and displayed the path to the perl script in the address bar. There was no email sent and I could not find the 'uploaded' file on the server. I checked the existing formmail.pl script/html and it works with email OK (but does not include a function to upload files).

I have the necessary permission to edit then upload the scripts but I am limited to ftp access. The cgi scripts are contained in a directory called '/cgi' and the html lives in a directory called '/web'. There was no directory called '/tmp' and I was not permmited to create one in '/' but I could create '/web/tmp'. I used 'web/tmp' as the location for the uploaded file.

Maybe I need to find or setup a directory (such as /tmp) that has the correct permissions to allow writing a new file? I found a directory '/files' , maybe I could use '/files' for the upload directory...

I only have ftp access to the UNIX server. However I probably could request a simple change to a system, directory or file permission/security setting.

Please describe the code I can use to debug the perl script. For example, a piece of code that would write out the current variables and display them in a html page, returned to the original html request.

By what process does the user's file get uploaded to the UNIX server? Is it a function of the html form field of type 'file' or is it required that the perl script read in the user's file-path from the form-field type 'file' and then conduct a simple ftp function to upload the file?
Is there a system setting or process block that restricts uploading of a file to the UNIX web server?

Could you write a simple script\html to confirm that the upload function is available?

It seems to me I am asking a lot from you. If you can help I am willing to help you in return with an increase in points awarded or whatever you may suggest, thanks.


PS. The 'attach_cv_details.pl' script looks just like what I'm after, thanks.

PPS. As of writing this comment all other previous comments are not shown on this page. I hope you get this message ok...
"Maybe I need to find or setup a directory (such as /tmp) that has the correct permissions to allow writing
a new file? I found a directory '/files' , maybe I could use '/files' for the upload directory..."

YES, that's one thing


so, as far as the upload, this is a cgi module upload script
here is the test form:

<FORM ENCTYPE="multipart-form/data" ACTION="perlscript.pl" METHOD="POST">


use CGI ':standard';

$temp="yourTEMPDirectory chmoded777";
print header, start_html;
print "I am going to try and upload a file from a form.";
my $fh=param('filef');
my $fn=$1;
my $buffer;
open FH, "$tmp/$fn";
print FH $buffer;
close FH;

try those out and let me know how it goes

don't forget about the chmod 777 tmpdir!!

Let me know,

gfergusAuthor Commented:
Thanks for all your help!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now