Forum Moderators: coopster

Message Too Old, No Replies

Please Help with PHP Email Form - Uploading Files

php email form file attachments

         

semenov419

4:45 am on Jul 8, 2010 (gmt 0)

10+ Year Member



Hi I am a newbie with PHP email forms and I am trying to configure e-mail form correctly for the website that I am building. I bought a template that came with PHP email form, everything works fine with the form except for attachments. Problem that I am facing is that this form allows only jpg files to be sent as attachments, and it gives those files temporary name. In my situation I need word, pdf and exel files to be sent as well. Below is the script from the form, can someone please advise on how can i modify the script so i will be able to receive word documents, pdf and exel files with their original file names instead of temporary names that form assigns to them.

Thank you very much.

 <? if($_POST) {
include('form_config.php');
if(eregi('.jpg',$_FILES[image][name])) {
$unid = uniqid();
move_uploaded_file($_FILES[image][tmp_name],'offer_uploads/'.$unid.'.jpg');
$urla = "http://www.globalmeattraders.com/offer_uploads/$unid.jpg";

jatar_k

2:45 pm on Jul 8, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can remove the eregi line or you could change it to use an array of extensions that you want to allow

maybe explode the file extension and check against an array

$filename_parts = explode();
$file_ext = $filename_parts[count($filename_parts) - 1];
$allowed_exts = array('pdf','xls','doc','jpg');
if (in_array($file_ext,$allowed_exts)) {
$unid = uniqid();
move_uploaded_file($_FILES[image][tmp_name],'offer_uploads/'.$unid.'.' . $file_ext);
}

you could add whatever extensions you need to the array

it then uses the original extension along with the unique id for the uploaded file

should work