two php form questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
polymaze
Forum Newbie
Posts: 2
Joined: Wed Oct 15, 2008 3:28 am

two php form questions

Post by polymaze »

Hello,
I have been having trouble getting a php uploader to work properly.

You can see the form here:
http://www.polymaze.funformentals.com/

and the files:
http://www.polymaze.funformentals.com/testform.zip

So far, it is for two reasons:
1. If the file upload input is left empty, I keep getting two warning messages. Rather than just not attaching a file.

Code: Select all

 
Warning: fread(): supplied argument is not a valid stream resource in /home/.eclair/polymaze/polymaze.funformentals.com/utilities/uploader.php on line 37
 
Warning: fclose(): supplied argument is not a valid stream resource in /home/.eclair/polymaze/polymaze.funformentals.com/utilities/uploader.php on line 38
 
2. The email that it sends isn't broken onto seperate lines, even though I have placed "\n" at the end of the parts I would like to have seperated.

For example:

Code: Select all

 
$body = "Client Name: $firstname $lastname\n Address: $address\n E-Mail: $email\n Phone: $phone\n Job Type: $jobtype\n Estimate: $estimate\n";
 
Any help would be greatly appreciated
Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: two php form questions

Post by requinix »

1) Here's a hint: if $_FILES[userfile][error] == 4 then there was no file uploaded.
Modify your code so that it only attaches the file if the error is zero (just because it isn't four doesn't mean the upload was okay).

2) Your email says it's in HTML format, so your data should be HTML. Or change the MIME type to text/plain.

3) There's only one PHP file. It'd be a lot nicer if you just posted that file rather than attach a ZIP file with a bunch of files we don't need.
polymaze
Forum Newbie
Posts: 2
Joined: Wed Oct 15, 2008 3:28 am

Re: two php form questions

Post by polymaze »

Thanks for the info, I'll give it a try.

Here is the uploader code.

Code: Select all

 
<?php
 
if(isset($_POST['submit']))  { 
 
// GRAB THE INPUT DATA FROM THE FORM
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['street'] . ", " . $_POST['city'] . ", " . $_POST['state'] . ", " . $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$bansqft = $_POST['banwid'] * $_POST['banhei'];
$bandouble = $_POST['bandouble'];
$banqua = $_POST['banqua'];
$vinsqft = $_POST['vinwid'] * $_POST['vinhei'];
$vinqua = $_POST['vinqua'];
$vintype = $_POST['vintype'];
$finish = $_POST['finish'];
$sides = $_POST['sides'];
$grommets = $_POST['grommets'];
 
// ATTACH THE INPUT DATA
$body = "Client Name: $firstname $lastname\n Address: $address\n E-Mail: $email\n Phone: $phone\n Job Type: $jobtype\n Estimate: $estimate\n";
 
// ATTACH THE UPLOADED FILE
$fileatt = $_FILES['userfile']['tmp_name'];         // Name of the file input on the form replaces 'file'
 
$file_pieces = split("\.",  $_FILES['userfile']['name']);
$orig_ext = $file_pieces[count($file_pieces)-1];    //Just in case you need the extension (ie: .jpg, .gif, etc.)
 
$fileatt_type = "application/octet-stream";         // File Type (this works for any file type)
$fileatt_name = $_REQUEST['firstname'] . "_" . $_REQUEST['lastname'] . "." . $orig_ext;
 
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
 
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
 
$headers = "From: ".$email_from;
 
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
 
$body .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$body . "\n\n";
 
$data = chunk_split(base64_encode($data));
 
$body .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
 
// CONNECT  THE EMAIL INFO
$email_from = $_POST['email'];          // Who the email is from 
$email_subject = "form submission";             // The Subject of the email
$email_txt = "email message";   // Message that the email has in it
$email_to = "email@email.com";          // Who the email is to
 
$ok = @mail($email_to, $email_subject, $body, $headers);
echo  "Form successful!";                       // continued if/else statement from top
 
} else {
 
echo "blarg!";
 
} 
 
?>
 
Post Reply