Uploading files


I’m trying to set up input forms in PHP (using HTML code in the modules) so that customers can send information to me. An optional part of that information can be 2 files (they should be graphics files). I’ve set it up with the proper INPUT type=“file” as well as setting the enctype and method (post), but it doesn’t work. I’ve used two different enctypes and the proper one (enctype=“multipart/form-data”) gives me nothing from the file field and the improper one (enctype=“x-www-form-encoded”) I get the paths of the files but not the files themselves. This is all using the formmail.cgi action.

Is it possible to have customer uploaded files sent through a form, processed through DreamHost and delivered via email?

Any help or insights would be greatly appreciated.



The source of this problem isn’t your form or Dreamhost, it is the formmail.cgi file that you’re trying to use. It supports any number of input fields, but not file uploads. You don’t get anything with the correct enctype, because it is ignoring uploaded files as designed. When you use the invalid enctype, the file field is coming through as a simple text input, which is why you’re getting the actual string in that field. Formmail details here: http://formmail.dreamhost.com/

You may be able to find a premade PHP handler page on the net, but you’ll need to write your own if not. You have a couple options that might prove useful. You could build a custom handler page that is tailored to your form, constructs an email from it, and includes the uploaded files as attachments.

Another option would be a two step process, that capitalizes on the flexibility of the formmail.cgi, and saves you the trouble of dealing with the mail creation aspects. You would create a PHP handler page that uploads the files to a predefined destination directory on your host, and then dumps the rest of the data into a form you build by looping over the post data. That form could then use javascript to submit itself to the formmail function, which would handle the rest of the process. Here are the PHP docs for the file upload process: http://www.php.net/manual/en/features.file-upload.php

BC Tech
Team Shocker