Solved

CGI/Perl script that includes file attachments

Posted on 2001-07-16
3
214 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
ID: 6291153
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
ID: 6302743
"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
ID: 6625791
Thanks for all your help!

Greg
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Scripting 3 144
Windows 2008 Server File need to monitor folder anytime file added, move to Z:\test 10 74
Adjust the position 3 65
Facebook React and SyntheticEvents 6 70
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 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