PDA

View Full Version : Attaching Files in web forms



southernman
10-26-2004, 03:54 PM
How do you make a web form to where it will upload the picture or file to an email address, like you can do in web forms. I would like to do the attach files to be sent to my email through a web form. Well guess what I am looking for is the correct codes to do so and if it is support by the current form processor on westhost servers.

Tom Howard
10-26-2004, 08:47 PM
I've seen ways to do this with PHP. There are some scripts at Hot Scripts (http://www.hotscripts.com/PHP/Scripts_and_Programs/Email_Systems/Email_Utilities/more2.html) that look promising.

CoffeyMate
12-31-2004, 09:18 AM
I would like to do the attach files to be sent to my email through a web form.

Perl Services has a script called Form Mailer with Attachments that does this. The script will cost you $20.

Description:

Allow your website visitors to attach files of any type to your form and have the files emailed to you! This very basic script lets you create your own form and have the contents e-mailed to you. Additionally, it allows users to attach files from their desktop hard drive, to the form they are submitting, all in one step.

We recently re-wrote the entire script and added new features to help you control the programs response to users.

In our first version, the file attachment limit was about 1.5 to 2 Mb, the new changes we've incorporated since then have blown the benchmarks through the roof. Clients use this program to send files 2MB, 5MB, 10MB and 20MB with no problems. The only limitation will be the server that the script is hosted on and the e-mail client used to receive the file. The programs upload handling has been used in other programs with files over 600MB in size (though we do not recommend files THAT big for e-mail!!!)

To see what we mean, fill in this brief demo form and select a file for attachment. Fill in YOUR e-mail address in the "Your E-Mail" field and we will send you the form results with the attachment so that you can see how quickly it works. Your email will not be recorded.

http://www.perlservices.net/en/programs/attachment_formmailer/index.shtml

wildjokerdesign
12-31-2004, 04:12 PM
The folks who updated the Matts Scripts have an alternative for the original called TFmail.pl that has the option to attach files to an email that is sent via a web form. I have tested the script on one of my accounts and it seems to work fine. The only drawback is that unlike the one CoffeyMate mentioned it is Free. :) Free means limited support since the folks who maintain the script are doing it on a volunteer basis. It can get a bit tricky when it comes to modifying the look although it is much easier I think then the original.

You can lear more about it at http://nms-cgi.sourceforge.net

Tom Howard
12-31-2004, 05:04 PM
I recently needed to do this, so I thought I'd code it up myself. Here's the basic code:

uploadexample.html

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h2>Upload Example</h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="upload_file"><br /><br />
<input type="submit" value="Upload">
</form>
</body>
</html>

upload.php

<?php
$acceptable_types = array("jpg" => 1, "jpeg" => 1, "gif" => 1, "png" => 1); //I wanted image files only
$min_size = 0;
$max_size = 100000;
$dir = "/var/www/html/uploads/";

$file_name = $_FILES['upload_file']['name'];
$file_size = $_FILES['upload_file']['size'];
$temp_name = $_FILES['upload_file']['tmp_name'];
$file_strings = explode(".", $file_name); //just in case the file has multiple '.'
$extension = $file_strings[count($file_strings) - 1]; //the last element in the array is the extension

//check type
if($acceptable_types[strtolower($extension)] != 1)
{
echo "Files of type: <b>" . $extension . "</b> are not accepted.";
//do something about it here
}
//check size
else if($file_size < $min_size)
{
echo "File is too small.";
//do something about it here
}
else if($file_size > $max_size)
{
echo "File is too big.";
//do something about it here
}
else
{
if(is_uploaded_file($temp_name)) //make sure it was an uploaded file
$result = move_uploaded_file($temp_name, $dir . $file_name); // $result true=successful
if($result)
echo "File uploaded successfully.";
else
echo "File upload unsuccessful.";
}
?>

I'm always looking to improve my style, so feel free to make suggestions for improvement :wink:

wildjokerdesign
12-31-2004, 07:51 PM
Nice Tom!

I like the fact that it is just the basics. I have fought integrating some codes into existing setups because they where so filled with extra calls and included files for handleing errors, visual output and other bells and whistles.

Thanks for posting.

CoffeyMate
01-01-2005, 02:35 PM
Free means limited support since the folks who maintain the script are doing it on a volunteer basis.
Free is like advice. You get what you pay for.

CoffeyMate
01-01-2005, 02:50 PM
As an aside, doesn't this defeat the purpose of the WestHost forums by diverting traffic to your Web site?

I have compiled some of the solutions on my forum found at: www.wildjokerdesign.com/board/

Tom Howard
01-01-2005, 03:24 PM
With nearly 1400 posts, Wildjoker is the WestHost forums.

(Jalal, FZ, Torrin, etc. being notable contributors as well)

CoffeyMate
01-01-2005, 03:40 PM
With nearly 1400 posts, Wildjoker is the WestHost forums.
Someone has way too much time on their hands.

Tom Howard
01-01-2005, 04:43 PM
Someone has way too much time on their hands.

Like someone who spends their New Year's day posting on the WestHost forum every couple of hours? :wink:

(that includes me too, it would seem ) :P

SJP
01-02-2005, 02:12 PM
Someone has way too much time on their hands.

You're just sore, because WJD pulled the rug out from your feet. But, I've learned there are plenty of people out there that either never hear or will pass up the opportunity, because they too are convinced if it is free it can't be very good.


Free is like advice. You get what you pay for.

I've contributed perl scripts for extracting pictures and helping to defeat SPAM and VERY FEW (if any) take me up on what I offer. Most people don't want to figure it out for themselves. They want everything handed to them on a silver platter. So don't worry. WJD hasn't made any lasting dents.

This is not a good place to try and peddle your wares! This is a place where webmasters help each other out and WJD among others has been very exemplary of that!.

Also something you didn't mention in your description. My ISP for instance sets limits on how large mail messages can be (2MB I believe). So while your pitch that Mailer can handle file sizes far in excess sounds great I can't help, but wonder how realistic it is.

SJP

CoffeyMate
01-03-2005, 04:37 PM
This is not a good place to try and peddle your wares!
pedĚdle
v. pedĚdled, pedĚdling, pedĚdles
v. tr.

To travel about selling (wares): peddling goods from door to door.

I'm not affiliated with, nor do I have any financial interest whatsoever in Perl Services.


Also something you didn't mention in your description. My ISP for instance sets limits on how large mail messages can be (2MB I believe). So while your pitch that Mailer can handle file sizes far in excess sounds great I can't help but wonder how realistic it is.
The description came from the Perl Services Web site. Apparently you missed the paragraph below. Test it for yourself.

"To see what we mean, fill in this brief demo form and select a file for attachment. Fill in YOUR e-mail address in the "Your E-Mail" field and we will send you the form results with the attachment so that you can see how quickly it works. Your email will not be recorded." (Clue: It's Perl Services "we," not mine.)

http://www.perlservices.net/en/programs/attachment_formmailer/index.shtml

SJP
01-03-2005, 06:07 PM
pedĚdle
v. pedĚdled, pedĚdling, pedĚdles
v. tr.

To travel about selling (wares): peddling goods from door to door.

Thank you Mr. Dictionary. Well you see the problem with blindly posting what is written on a web-site is that:

1. There is nothing in the law that says people can't exagerate
2. If you aren't famaliar with the medium then you can't very well know if they live upto their claims or there are other implications

Isn't that right?

In their defense I will say that perhaps not all ISPs impose limits and probably not internally where files of that maginute would not be unordinary.

In your defense I will say you were just trying to be helpful and I took it the wrong way. Sorry, I misjudged you.


SJP