Adding File Upload option

I have a generic form on my website, but I’d like to add the option to upload a file with the form - ultimately sending the document to me as an attachment. I’ve found PHP codes online to try to get it to work, but I can’t figure it out. First, I guess I need to know if this is possible (which I’m pretty certain it is) and second, I need help with the code.

Here is the html code for the actual form:

<form action="sr.php" method="post" enctype="multipart/form-data" name="Name" target="_parent" id="Name"> <table width="722" border="0"> <tr> <td width="193">&nbsp;</td> <td width="161"><div align="left" class="style9">Name</div></td> <td width="199"><span id="sprytextfield5"> <label> <input name="Name" type="text" id="Name" size="45"> </label> <span class="textfieldRequiredMsg"></span></span></td> <td width="151">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Company Name</div></td> <td><span id="sprytextfield4"> <input name="Company" type="text" id="Company" size="45"> <span class="textfieldRequiredMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Account Number</div></td> <td><span id="sprytextfield3"> <input name="MID" type="text" class="style2" id="MID" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Email Address</div></td> <td><span id="sprytextfield2"> <input name="Email" type="text" class="style2" id="Email" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Phone Number</div></td> <td><span id="sprytextfield6"> <input name="Phone" type="text" class="style2" id="Phone" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td colspan="4"><div align="left"> <span id="sprycheckbox2"> <label></label> </span> <table width="100%" border="0" cellpadding="2"> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> <br> </div></td> </tr> <tr> <td colspan="4"><div align="left"> <span id="sprycheckbox1"> <label> <span class="style1"> <span class="style2"> <input type="checkbox" name="Certify" id="Certify"> </span></span></label> </span><span class="style9"> I declare that I have read and understand the guidelines and that I comply within these guidelines. </span>.<br> </div></td> </tr> <tr> <td colspan="4"><div align="right"><span class="style12"> <label> *All Fields Are Required <div align="center"> <input type="submit" name="Subject" value="Submit">

And here is my php code:
[php]<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'I am Compliant ';

// Your email address. This is where the form information will be sent.
$emailadd = ‘[email protected]’;

// Where to redirect after form is processed.
$url = ‘/confirmation.html’;

// Makes all fields required. If set to ‘1’ no field can not be empty. If set to ‘0’ any or all fields can be empty.
$req = ‘1’;

// --------------------------Do not edit below this line--------------------------
$text = “Results from form:\n\n”;
$space = ’ ';
$line = ’
‘;
foreach ($_POST as $key => $value)
{
if ($req == ‘1’)
{
if ($value == ‘’)
{echo “$key is empty”;die;}
}
$j = strlen($key);
if ($j >= 20)
{echo “Name of form element $key cannot be longer than 20 characters”;die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ’ ‘;}
$value = str_replace(’\n’, “$line”, $value);
$conc = “{$key}:$space{$value}$line”;
$text .= $conc;
$space = ’ ';
}
mail($emailadd, $subject, $text, ‘From: ‘[‘Email’]’’);

echo ‘’;
?>
[/php]

Oh…and here is the script that I found online for uploading, but not sure it is even what I actually need.

[code]

Select a file:
Upload File

[/code] ....and.... [php]<?php // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation. $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB). $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory).

$filename = $_FILES[‘userfile’][‘name’]; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,’.’), strlen($filename)-1); // Get the extension from the filename.

// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die(‘The file you attempted to upload is not allowed.’);

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES[‘userfile’][‘tmp_name’]) > $max_filesize)
die(‘The file you attempted to upload is too large.’);

// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die(‘You cannot upload to the specified directory, please CHMOD it to 777.’);

// We’ll start handling the upload in the next step

?>[/php]

LOL, of course it can be done! ANYTHING can be done with programming, just some is more complicated than others. Yours is easy. But, I will let other explain it… Here are two links to two different ways to do this.
Either will work. It is just an issue of placing the headers correctly. If you can not figure either out, let us know and post what you have at that point. Good luck, let us know…

http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script
http://webcheatsheet.com/PHP/send_email_text_html_attachment.php (3rd section)

From the links provided, it looks like I will have to completely redo the php code. Also, they seem to talk more about using php emails, whereas I am simply trying to add it to a form. (Does that make sense?) - it’s Friday and I am very ready for the weekend!

I was hoping it was just a few lines that needed to be added to my existing code. Like this one: [code]

Select a file:
Upload File

[/code]

but that completely messes up the aesthetics of my site since I am inserting it into the middle of an existing form. But if I remove the begin and end of the form/formaction, it doesn’t perform the function.

I suppose I need to accomplish two things and I hoping for a little more direction, I am a rookie.

  1. I need to create an browse and upload part to my html form.
  2. I need to adjust my existing PHP file to tell it to send the attachment as part of the form submission.

Well, yes, you would have to add a line something like this:

   <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />

INSIDE the form that was your first code you posted. I would suggest just under the PHONE section.

Then, in the section of the second part you posted just before you send the mail, you would have to put in your attachment. Not sure as I am leaving, so no time to test, but like this:

$attachment = chunk_split(base64_encode(file_get_contents(’$_POST[‘userfile’])));
$header .= “Content-Type: text/html; charset=‘iso-8859-1’\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n”;
$header .= “Content-Type: application/TYPE-OF-FILE;” . $_POST[‘userfile’] . “\r\n”;
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n”;

So, what this does is basically grab the file content, create a header with linefeeds to set up the data for sending. The TYPE-OF-FILE would have to be changed to the type of file you are sending. If it is a picture instead of a zip file, it would not be application/zip, but, maybe image/jpg… I can help you sort this our further tomorrow, but I am leaving shortly for the evening.

Note, the header for an attachment file is different for each type of file. So, it is different for a text file, JPG picture, GIF picture, exe file, PNG picture, or any other. There are ways to set up the header for each type, but, that brings us up to another question. What are you allowing your user to send? If it is just a picture, then that is easy. But, there are several types of pictures. It might be easier to just use PHP to upload the file to your server (easy code, filetypes do not matter!) and just send the filename inside the email. In this manner, the PHP code would just upload the file to the server in a folder you set and then just add the name to the email. (Easier code than adding attachments to emails.)

Anyway, I can help more tomorrow or Monday…

I was able to successfully add to the form, but doing the php file I’m not as successful. I’m trying to place it just just before

[php]mail($emailadd, $subject, $text, ‘From: ‘.$_POST[‘Name’].’ <’.$_POST[‘Email’].’>’);[/php]

but viewing it in Dreamweaver reveals that something is wrong as the it causes the “colors” of the various commands to change. Wheres the “mail(” part from above is typically blue, once I paste the script it, it turns everything below the code red. Doesn’t this mean I’m missing some sort of deliminator?

Also, the users using will need the ability to upload a scanned document - which could be a pdf, jpg, gif, bmp or doc. I suppose we can just have some text in there that only allows for either pdf or jpg, but I’ll need your help in setting that up.

Thanks!

Okay, post your code before the mail function so I can look at the headers you are creating…
But, let’s be clear on this…

You are allowing various files to be uploaded… So, why not just have the PHP code upload the files
for you to the server and you can deal with them. (Instead of attaching them to an email???)

If you are just uploading a file to YOUR server, it is only a couple lines of code. But, sending an attachment
means you have to have a different header for each possible filetype.

So, when they send a file, do you have one place you are storing it or must it be inside an email. Either will work, but, the code is different for each. I should be around tomorrow for about 24 hours, so I will help more then, if you are around!.. Let me know the details on why you want to upload a file via email instead of directly to the server folder…

Here is the php code, let me know if the code you suggested should be input somewhere else.
[php]<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'I am Compliant ';

// Your email address. This is where the form information will be sent.
$emailadd = ‘[email protected]’;

// Where to redirect after form is processed.
$url = ‘/confirmation.html’;

// Makes all fields required. If set to ‘1’ no field can not be empty. If set to ‘0’ any or all fields can be empty.
$req = ‘1’;

// --------------------------Do not edit below this line--------------------------
$text = “Results from form:\n\n”;
$space = ’ ';
$line = ’
';
foreach ($_POST as $key => $value)
{
if ($req == ‘1’)
{
if ($value == ‘’)
{echo “$key is empty”;die;}
}
$j = strlen($key);
if ($j >= 20)
{echo “Name of form element $key cannot be longer than 20 characters”;die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ’ ';}
$value = str_replace(‘n’, “$line”, $value);
$conc = “{$key}:$space{$value}$line”;
$text .= $conc;
$space = ’ ‘;
}
$attachment = chunk_split(base64_encode(file_get_contents(’$_POST[‘userfile’])));
$header .= “Content-Type: text/html; charset=‘iso-8859-1’\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n”;
$header .= “Content-Type: application/TYPE-OF-FILE;” . $_POST[‘userfile’] . “\r\n”;
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n”;

mail($emailadd, $subject, $text, ‘From: ‘[‘Email’]’’);

echo ‘’;
[/php]

The reason I would like the file to be attached to the email is because we are expecting thousands that reply to it with the attachments. And since I am the only one with access to the ftp drop box, I want the ease of simply being able to forward the email to another team member at our organization instead of having to login, find the file, download it and then attach it to the record.

Yes, you are almost there… Using both, your old code and the new code I gave you, it will work.
So, change the code you have with these minor changes:
[php]
$attachment = chunk_split(base64_encode(file_get_contents(’$_POST[‘userfile’])));
$header = "From: " . $email . “\r\n”;
$header .= “Content-Type: text/html; charset=‘iso-8859-1’\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n”;
$header .= “Content-Type: application/TYPE-OF-FILE;” . $_POST[‘userfile’] . “\r\n”;
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n”;

mail($emailadd, $subject, $text, $header);
[/php]
So, this should work, but, needs to be debugged. How you do this is test it and just before the mail command, use this code:
[php]
echo $header;
die("…");
[/php]
What this will do is print your header and then stop so you can see the header before it is sent.
If the header looks correct, then remove the two debugging lines and try it again and see if you receive
the email with the attached file. Good luck!

Here is what I have. I get the email, but it does not debug when I test the site.

[php]$attachment = chunk_split(base64_encode(file_get_contents(’$_POST[‘userfile’])));
$header = "From: " .$_POST[‘Name’].’ <’.$_POST[‘Email’]. “\r\n”;
$header .= “Content-Type: text/html; charset=‘iso-8859-1’\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n”;
$header .= “Content-Type: application/pdf;” . $_POST[‘userfile’] . “\r\n”;
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n”;

echo $header;
die("…");

mail($emailadd, $subject, $text, $header);[/php]

Maybe I’m doing something wrong in my actual HTML form that’s not catching the file? I inserted your code after the phone upon your recommendation.

<form action="sr.php" method="post" enctype="multipart/form-data" name="Name" target="_parent" id="ID"> <table width="722" border="0"> <tr> <td width="193">&nbsp;</td> <td width="161"><div align="left" class="style9">Name</div></td> <td width="199"><span id="sprytextfield5"> <label> <input name="Name" type="text" id="Name" size="45"> </label> <span class="textfieldRequiredMsg"></span></span></td> <td width="151">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Company Name</div></td> <td><span id="sprytextfield4"> <input name="Company" type="text" id="Company" size="45"> <span class="textfieldRequiredMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Account Number</div></td> <td><span id="sprytextfield3"> <input name="MID" type="text" class="style2" id="MID" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Email Address</div></td> <td><span id="sprytextfield2"> <input name="Email" type="text" class="style2" id="Email" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Phone Number</div></td> <td><span id="sprytextfield6"> <input name="Phone" type="text" class="style2" id="Phone" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td colspan="4"><div align="left"> <span id="sprycheckbox2"> <label></label> </span> <table width="100%" border="0" cellpadding="2"> <tr> <td><label for="file"> <div align="center">Select a file: </label> <input type="file" name="userfile" id="file"> <br /> &nbsp;</div></td> </tr> </table> <br> </div></td> </tr> <tr> <td colspan="4"><div align="left"> <span id="sprycheckbox1"> <label> <span class="style1"> <span class="style2"> <input type="checkbox" name="Certify" id="Certify"> </span></span></label> </span><span class="style9"> I declare that I have read and understand the Guidelines and that I comply within these guidelines.</span>.<br> </div></td> </tr> <tr> <td colspan="4"><div align="right"><span class="style12"> <label> *All Fields Are Required <div align="center"> <input type="submit" name="I am Compliant" value="Submit"> </div> </label></td> </tr> </table> </form>

Thanks for you help!

Well, there is an error, maybe mine or maybe yours, either way this:
$attachment = chunk_split(base64_encode(file_get_contents(’$_POST[‘userfile’])));

Should be this:
$attachment = chunk_split(base64_encode(file_get_contents($_POST[‘userfile’])));
There was an extra quote in it…

Let us know if that fixes it…

I corrected the extra quote, but the attachment still isn’t coming through. Any other suggestions…do you think something is wrong with the file type (you had mentioned you have to specify which file type). The attachement I’m testing with is a pdf.

[php]$attachment = chunk_split(base64_encode(file_get_contents($_POST[‘userfile’])));
$header = "From: " .$_POST[‘Name’].’ <’.$_POST[‘Email’]. “\r\n”;
$header .= “Content-Type: text/html; charset=‘iso-8859-1’\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n”;
$header .= “Content-Type: application/pdf;” . $_POST[‘userfile’] . “\r\n”;
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n”;

echo $header;
die("…");

mail($emailadd, $subject, $text, $header);[/php]

So, it’s not showing the header? Then, your code is not getting to the mail function…

Well, I went back to your original code and noticed this error:
This line near the begginning:
$emailadd = ‘[email protected]’;
Actually has a meta-quote for the first part and a normal one at the end.
Should be:
$emailadd = ‘[email protected]’;

If that solves it, great. If not, please repost your php codes. Good luck.

The emails are coming over to my email client, they just aren’t including the attached file.

Here’s the complete PHP…
[php]<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'I am Compliant from ‘.$_POST[‘MID’].’ ';

// Your email address. This is where the form information will be sent.
$emailadd = ‘[email protected]’;

// Where to redirect after form is processed.
$url = ‘compliance/confirmation.html’;

// Makes all fields required. If set to ‘1’ no field can not be empty. If set to ‘0’ any or all fields can be empty.
$req = ‘1’;

// --------------------------Do not edit below this line--------------------------
$text = “I declare that I have read and understand the Guidelines and that I comply within these guidelines.
:\n\n”;
$space = ’ ‘;
$line = ’
‘;
foreach ($_POST as $key => $value)
{
if ($req == ‘1’)
{
if ($value == ‘’)
{echo “$key is empty”;die;}
}
$j = strlen($key);
if ($j >= 20)
{echo “Name of form element $key cannot be longer than 20 characters”;die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ’ ‘;}
$value = str_replace(’\n’, “$line”, $value);
$conc = “{$key}:$space{$value}$line”;
$text .= $conc;
$space = ’ ‘;
}
$attachment = chunk_split(base64_encode(file_get_contents($_POST[‘userfile’])));
$header = "From: " .$_POST[‘Name’].’ <’.$_POST[‘Email’]. “\r\n”;
$header .= “Content-Type: text/html; charset=‘iso-8859-1’\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n”;
$header .= “Content-Type: application/pdf;” . $_POST[‘userfile’] . “\r\n”;
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n”;

echo $header;
die("…");

mail($emailadd, $subject, $text, $header);

echo ‘’;
?>
[/php]

and here is the form portion of the html.

<form action="sr.php" method="post" enctype="multipart/form-data" name="Name" target="_parent" id="ID"> <table width="722" border="0"> <tr> <td width="193">&nbsp;</td> <td width="161"><div align="left" class="style9">Name</div></td> <td width="199"><span id="sprytextfield5"> <label> <input name="Name" type="text" id="Name" size="45"> </label> <span class="textfieldRequiredMsg"></span></span></td> <td width="151">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Company Name</div></td> <td><span id="sprytextfield4"> <input name="Company" type="text" id="Company" size="45"> <span class="textfieldRequiredMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Account Number</div></td> <td><span id="sprytextfield3"> <input name="MID" type="text" class="style2" id="MID" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Email Address</div></td> <td><span id="sprytextfield2"> <input name="Email" type="text" class="style2" id="Email" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><div align="left" class="style9">Phone Number</div></td> <td><span id="sprytextfield6"> <input name="Phone" type="text" class="style2" id="Phone" size="54"> <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td> <td>&nbsp;</td> </tr> <tr> <td colspan="4"><div align="left"> <span id="sprycheckbox2"> <label></label> </span> <table width="100%" border="0" cellpadding="2"> <tr> <td><label for="file"> <div align="center">Select a file: </label> <input type="file" name="userfile" id="file"> <br /> &nbsp;</div></td> </tr> </table> <br> </div></td> </tr> <tr> <td colspan="4"><div align="left"> <span id="sprycheckbox1"> <label> <span class="style1"> <span class="style2"> <input type="checkbox" name="Certify" id="Certify"> </span></span></label> </span><span class="style9"> I declare that I have read and understand the Guidelines and that I comply within these guidelines. </span>.<br> </div></td> </tr> <tr> <td colspan="4"><div align="right"><span class="style12"> <label> *All Fields Are Required <div align="center"> <input type="submit" name="I am Compliant" value="Submit"> </div> </label></td> </tr> </table> </form>

Maybe it has something to do with me specifying the files types - like you said in one of your original posts?

Yes, it also may have something to do with browsers. I just found a note on a site that setting PDF header info sometimes have to be changed. Try it on both FireFox and IE. Then, let me know what happens… I will read some more for you.

I’ve tried it in IE, Firefox and Chrome to no avail. Let’s go back and try to do it the other way…where the file is uploaded to my server…with this method, how will I know what the name of the file is. Also, can I create a directory on my server of where they get dropped?

Thanks!

Late late last night, I found that the problem is the headers in the email. It seems you have to encode the file in chunks in a certain order. If you want to do it by email, I can set up a test page on my server and solve it for you. I think it is just the order of the headers.

But, if you want to do it the other way, show the code of what you have. Let me know soon which way you want to try this. Either should be able to work…

Let’s try it with an upload to the server. I don’t know the code for that. Since we are going this route, what I’d like to do it create a directory on my server that the files will be stored in. Once I’ve done that, I need to know what the code is for uploading the file to the server. Also, can we have the php name the file once it’s uploaded, or will the email that comes through simply tell me the name of the file (that the user defined) that was uploaded so I can locate it on the server?

Thank you for all your help on this. It is greatly appreciated.

Well, in your form code, you have a input file with the name=“userfile”. So, this code is how to upload it to the server with a renaming of the file. You could rename it using the user’s ID or something like that which would make it unique to the user. You could even make the new name of the file be userID-date-oldfilename, or any other such name that would make it easier for you to locate. That would depend on how long you keep the file and what you are planning on doing with it. Here is some sample code for you to start with…
[php]

<?php // Get the file from the posted form... $file_name = $_FILES['userfile']['name']; // Now create some number to make the file unique. This could be the date. // So, if the user changes his data and resends it, it will create a new unique number. // We will use a random 4 digit to add to our file name for this example... $random_digit=rand(0000,9999); //Combine random digit to you file name to create new file name ,use dot (.) to combine these two variables $new_file_name = $random_digit . $file_name; //Set where you want to store files, in this example we keep file in folder "upload" //If you want to create a separate folder for each user, that could be done with DIR commands... $path= "upload/" . $new_file_name; //Check for input filename just in case user forgot it... If there, do upload... if($userfile !=none) { if(copy($_FILES['userfile']['tmp_name'], $path)) { echo "Successful
"; echo "File Name :" . $new_file_name."
"; echo "File Size :" . $_FILES['userfile']['size']."
"; echo "File Type :" . $_FILES['userfile']['type']."
"; } else { echo "Error, file did not upload correctly!"; } } ?>

[/php]
Something like this will upload the file, change the filename and report back with the size and type of the file.
It is not tested, but, should work for you. Try it and look at the server folder to see if the file is uploaded.
If it does not work for you, let us know… Good luck.

Okay. I still can’t get this dang thing to work.

To start fresh, the webpage that the form field is on and the php file is located is in a directory called Compliance.
I create a new directory for the uploaded files to be put in is call Confirmation.

Here is the php code that I am using.
[php]<?php
$subject = 'I am Compliant from ‘.$_POST[‘MID’].’ ';
$emailadd = ‘[email protected]’;
$url = ‘compliance/confirmation.html’;
$req = ‘1’;
$text = “I declare that I have read and understand the Guidelines and that I comply within these guidelines.
:\n\n”;
$space = ’ ';
$line = ’
‘;
foreach ($_POST as $key => $value)
{
if ($req == ‘1’)
{
if ($value == ‘’)
{echo “$key is empty”;die;}
}
$j = strlen($key);
if ($j >= 20)
{echo “Name of form element $key cannot be longer than 20 characters”;die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ’ ‘;}
$value = str_replace(’\n’, “$line”, $value);
$conc = “{$key}:$space{$value}$line”;
$text .= $conc;
$space = ’ ';
}

$file_name = $_FILES[‘userfile’][’’.$_POST[‘MID’].’’];
$random_digit=rand(0000,9999);
$new_file_name = $file_name . $random_digit;
$path= “Confirmation/” . $new_file_name;
if($userfile !=none) {
if(copy($_FILES[‘userfile’][‘tmp_name’], $path)) {
echo “Successful
”;
echo “File Name :” . $new_file_name."
";
echo “File Size :” . $_FILES[‘userfile’][‘size’]."
";
echo “File Type :” . $_FILES[‘userfile’][‘type’]."
";
} else {
echo “Error, file did not upload correctly!”;
}

mail($emailadd, $subject, $text, $header);

echo ‘’;
?>
[/php]

When I try to test the form on the website, there are no error messages, and I get the confirmation email, however no file is uploaded to the service in the destination I specified.
Any ideas??

Okay, I am looking at your file upload code. Give me a couple minutes…
But, in the meantime, I am curious! What is this code supposed to do???
$j = strlen($key);

$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ’ ‘;}
$value = str_replace(’\n’, “$line”, $value);
$conc = “{$key}:$space{$value}$line”;
$text .= $conc;
$space = ’ ';

Just nosey!

Sponsor our Newsletter | Privacy Policy | Terms of Service