Solved

CGI/Perl script that includes file attachments

Posted on 2001-07-16
3
206 Views
Last Modified: 2013-12-25
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.

Thanks

Greg
0
Comment
Question by:gfergus
  • 2
3 Comments
 

Author Comment

by:gfergus
Comment Utility
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.

Greg

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...
0
 
LVL 8

Accepted Solution

by:
bebonham earned 100 total points
Comment Utility
"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

umm,

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

<HTML>
<HEAD><TITLE>UNTITLED></TITLE></HEAD>
<BODY>
<FORM ENCTYPE="multipart-form/data" ACTION="perlscript.pl" METHOD="POST">
<INPUT TYPE="FILE" NAME="filef">
<INPUT TYPE="SUBMIT">
</FORM>
</BODY>
</HTML>

----------------------perscript.pl

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');
$fh=~/.*[\/\\]([^\\\/]+)/;
my $fn=$1;
my $buffer;
open FH, "$tmp/$fn";
while(read($fh,$buffer,1024))
{
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,

Bob
0
 

Author Comment

by:gfergus
Comment Utility
Thanks for all your help!

Greg
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

728 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

11 Experts available now in Live!

Get 1:1 Help Now