Menu
I’ve made a webform, where a user can enter his/her email, upload his/her resume and write a cover letter if wanted. Now I made a php, and ist sending me the cover letter and the email, but not the uploaded file! Is there a way, that an uploaded file can be send as attachment? If yes, does anyone know how to do this?
Fanx
[code=php]
<?
$to="[email protected]";
$message=" The following Resume was posted:nn
$covernn";
//open the file
$fp = fopen( $upload_name, "r");
//read the file into variables
$file = fread( $fp, $upload_size );
$file = chunk_split(base64_encode($file));
//get a random 32-character hexadecimal number
$num = md5( time() );
//define the main headers
$hdr = "From:$emailrn";
$hdr .= "MIME-Version: 1.0rn";
$hdr .= "Content-Type: multipart/mixedrn ";
$hdr .= "boundary=$numrn";
$hdr .= "--$numrn";
//define the message body
$hdr .= "Content-Type: text/htmlrn";
$hdr .= "Content-Transfer-Encoding: 64bitrnn";
$hdr .= "$messagern";
$hdr .= "--$numrn";
//define the attachment section
$hdr .= "Content-Type: $upload_type; ";
$hdr .= "name="$upload_name"rnn";
$hdr .= "$filern";
$hdr .= "--$num--rn";
If(mail($to,"Resume",$email,$hdr)){
echo "Thank you for your resume.";
}
else {
echo "There was a problem trying to send your resume. Please try again and make sure, everything is filled in correctly!";
}
?>
[/code]
[code=php]<?
$to="[email protected]";
$message=" The following Resume was posted:nn
$covernn";
//read the file into a variable
$file = file_get_contents($upload_name);
$file = chunk_split(base64_encode($file));
//get a hopefully unique boundary.
$num = md5(time());
//define the main headers
$hdr = "From:$emailrn";
$hdr .= "MIME-Version: 1.0rn";
$hdr .= "Content-Type: multipart/mixedrn ";
$hdr .= "boundary=$numrn";
$body .= "$messagern--$numrn";
// body goes here incase someone can't use multipart emails, rare but can happen.
$body .= "Content-Type: text/htmlrn";
$body .= "Content-Transfer-Encoding: 64bitrnn";
$body .= "$messagern";
$body .= "--$numrn";
//define the attachment section
$body .= "Content-Type: $upload_type; ";
$body .= "name="$upload_name"rnn";
$body .= "$filern";
$body .= "--$num--rn";
If(mail($to,"Resume",$body,$hdr)){
echo "Thank you for your resume.";
}
else {
echo "There was a problem trying to send your resume. Please try again and make sure, everything is filled in correctly!";
}
?>
[/code]
try that edit. ?[code=php]if(!is_file($upload_name)){
echo "$upload_name cannot be found.";
};[/code]
[code=php]// get unique file name.
$xname = basename($_FILES['uploadedfile']['name'])
$xpath =uniqid() .basename($_FILES['uploadedfile']['name']);
if(!move_uploaded_file($_FILES['UPLOADFORMFEILDNAME']['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
};
/// mail script goes here as before,
/// the file to open with file_get_contents is $xpath,
/// and the file name is $xname.
// after your mail script remove the file from the server to save space.
unlink($xpath);[/code]
die is better than exit, and I spelt exit wrong anyway ?[code=php]
<?
// get unique file name.
$xname = basename($_FILES['uploadedfile']['name'])
$xpath =uniqid() .basename($_FILES['uploadedfile']['name']);
if(!move_uploaded_file($_FILES['upload']['tmp_name'], $xpath)){
ecit("There was an error uploading the file, please try again!");
};
$to="[email protected]";
$message=" The following Resume was posted:nn
$covernn";
//read the file into a variable
$file = file_get_contents($xpath);
$file = chunk_split(base64_encode($file));
//get a hopefully unique boundary.
$num = md5(time());
//define the main headers
$hdr = "From:$emailrn";
$hdr .= "MIME-Version: 1.0rn";
$hdr .= "Content-Type: multipart/mixedrn ";
$hdr .= "boundary=$numrn";
$body .= "$messagern--$numrn";
// body goes here incase someone can't use multipart emails, rare but can happen.
$body .= "Content-Type: text/htmlrn";
$body .= "Content-Transfer-Encoding: 64bitrnn";
$body .= "$messagern";
$body .= "--$numrn";
//define the attachment section
$body .= "Content-Type: $xpath; ";
$body .= "name="$xname"rnn";
$body .= "$filern";
$body .= "--$num--rn";
If(mail($to,"Resume",$body,$hdr)){
echo "Thank you for your resume.";
}
else {
echo "There was a problem trying to send your resume. Please try again and make sure, everything is filled in correctly!";
}
// after your mail script remove the file from the server to save space.
unlink($xpath);
?>
[/code]
"Content-Type: $xpath;";
add it like so:"Content-Type: $xpath;rn";
[code=php]
$body .= "Content-Type: text/htmlrn ";
[/code]
[code=php]
$only_allow_word = true;
$fname = "YOUR FORM FEILD NAME GOES HERE";
$xname = basename($_FILES[$fname]['name'])
$xpath =uniqid() .basename($_FILES[$fname]['name']);
if($only_allow_word && !preg_match("/.doc$/i", $xname)){
die("sorry, microsoft word format only please.");
};
if(!move_uploaded_file($_FILES[$fname]['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
};[/code]
final edit there. sorry for the 2 botched edits.[code=php]
<?
$only_allow_word = true;
$fname = "YOUR FORM FEILD NAME GOES HERE";
$xname = basename($_FILES[$upload]['name'])
$xpath =uniqid() .basename($_FILES[$upload]['name']);
if($only_allow_word && preg_match("/.doc$/i", $xname)){
die("sorry, microsoft word format only please.");
};
if(!move_uploaded_file($_FILES[$fname]['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
};
$to="[email protected]";
$message=" The following Resume was posted:nn
$covernn";
//read the file into a variable
$file = file_get_contents($xpath);
$file = chunk_split(base64_encode($file));
//get a hopefully unique boundary.
$num = md5(time());
//define the main headers
$hdr = "From:$emailrn";
$hdr .= "MIME-Version: 1.0rn";
$hdr .= "Content-Type: multipart/mixedrn ";
$hdr .= "boundary=$numrn";
$body .= "$messagern--$numrn";
// body goes here incase someone can't use multipart emails, rare but can happen.
$body .= "Content-Type: text/htmlrn";
$body .= "Content-Transfer-Encoding: 64bitrnn";
$body .= "$messagern";
$body .= "--$numrn";
//define the attachment section
$body .= "Content-Type: application/mswordrn ";
$body .= "name="$xname"rnn";
$body .= "$filern";
$body .= "--$num--rn";
If(mail($to,"Resume",$body,$hdr)){
echo "Thank you for your resume.";
}
else {
echo "There was a problem trying to send your resume. Please try again and make sure, everything is filled in correctly!";
}
// after your mail script remove the file from the server to save space.
unlink($xpath);
?>
[/code]
[code=html]
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Upload your résumé</title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<!--webbot bot="FileUpload" U-File="_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" B-Reverse-Chronology="FALSE" S-Destination="Uploads/" S-Category S-Assignedto S-ReviewStatus B-Process-MetaInfo="FALSE" S-Builtin-Fields startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><input TYPE="hidden" NAME="_charset_" VALUE="windows-1252"><!--webbot bot="FileUpload" i-checksum="58985" endspan --><p> </p>
<blockquote>
<p>Email:
<input name="email" type="text" id="email">
</p>
<p> Upload your résumé:
<input name="upload" type="file" id="upload" size="20">
</p>
</blockquote>
<p> </p>
<p>If you want to add a cover letter, or any additional information (max. 1000 char.):</p>
<p>
<textarea name="cover" cols="100" rows="10" id="cover"></textarea>
</p>
<p> </p>
<p><input type="submit" value="Upload" name="B1"> <input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
[/code]
[code=php]
<?
$only_allow_word = true;
$fname = "$upload";
$xname = basename($_FILES[$fname]['name'])
$xpath =uniqid() .basename($_FILES[$fname]['name']);
echo "pass line X";
if($only_allow_word && preg_match("/.doc$/i", $xname)){
die("sorry, microsoft word format only please.");
};
if(!move_uploaded_file($_FILES[$fname]['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
};
echo "pass line X";
$to="[email protected]";
$message=" The following Resume was posted:nn
$covernn";
//read the file into a variable
$file = file_get_contents($xpath);
$file = chunk_split(base64_encode($file));
//get a hopefully unique boundary.
echo "pass line X";
$num = md5(time());
//define the main headers
$hdr = "From:$emailrn";
$hdr .= "MIME-Version: 1.0rn";
$hdr .= "Content-Type: multipart/mixedrn ";
$hdr .= "boundary=$numrn";
echo "pass line X";
$body .= "$messagern--$numrn";
// body goes here incase someone can't use multipart emails, rare but can happen.
$body .= "Content-Type: text/htmlrn";
$body .= "Content-Transfer-Encoding: 64bitrnn";
$body .= "$messagern";
$body .= "--$numrn";
echo "pass line X";
//define the attachment section
$body .= "Content-Type: application/mswordrn ";
$body .= "name="$xpath"rnn";
$body .= "$filern";
$body .= "--$num--rn";
echo "pass line X";
If(mail($to,"Resume",$body,$hdr)){
echo "Thank you for your resume.";
}
else {
echo "There was a problem trying to send your resume. Please try again and make sure, everything is filled in correctly!";
} echo "pass line X";
// after your mail script remove the file from the server to save space.
unlink($xpath);
echo "pass line X";
?>
[/code]
[code=php]$fname = "$upload";
$xname = basename($_FILES[$fname]['name'])
[/code]
I'm sure that's an error, 2 things will happen with that script, firstly if you have auto variables active it will default to the files name, then be unable to fine an upload feild with that name, the second is that you don't have them active, $upload will be empty and the whole thing fails terribly. [code=php]$fname = "upload";
$xname = basename($_FILES[$fname]['name'])
[/code]
removing the $ will give you the input name which is required by the rest of the script.[code=php]<?php
$only_allow_word = true;
$fname = "upload";
$xname = basename($_FILES[$fname]['name']);
$xpath = uniqid().$xname;
if($only_allow_word && !preg_match("/.doc$/i", $xname)){
die("sorry, microsoft word format only please.");
};
if(!move_uploaded_file($_FILES[$fname]['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
};
$to="[email protected]";
$message=" The following Resume was posted:nn
${_POST['cover']}nn";
//read the file into a variable
$file = file_get_contents($xpath);
$file = chunk_split(base64_encode($file));
//get a hopefully unique boundary.
$num = md5(time());
//define the main headers
$hdr = "From:$emailrn";
$hdr .= "MIME-Version: 1.0rn";
$hdr .= "Content-Type: multipart/mixedrn ";
$hdr .= "boundary=$numrn";
$body = "$messagern--$numrn";
// body goes here incase someone can't use multipart emails, rare but can happen.
$body .= "Content-Type: text/htmlrn";
$body .= "Content-Transfer-Encoding: 64bitrnn";
$body .= "$messagern";
$body .= "--$numrn";
//define the attachment section
$body .= "Content-Type: application/mswordrn ";
$body .= "name="$xpath"rnn";
$body .= "$filern";
$body .= "--$num--rn";
If(mail($to,"Resume",$body,$hdr)){
echo "Thank you for your resume.";
}
else {
echo "There was a problem trying to send your resume. Please try again and make sure, everything is filled in correctly!";
}
// after your mail script remove the file from the server to save space.
unlink($xpath);
?>[/code]
[code=php]
<?php
$only_allow_word = true;
$fname = "upload";
$xname = basename($_FILES[$fname]['name']);
$xpath = uniqid().$xname;
// here's the bit to add:
$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');
($_FILES[$fname]['error'] == 0)
or die($errors[$_FILES[$fname]['error']]);
@is_uploaded_file($_FILES[$fname]['tmp_name'])
or die('not an HTTP upload');
// resume:
if($only_allow_word && !preg_match("/.doc$/i", $xname)){
die("sorry, microsoft word format only please.");
};
if(!move_uploaded_file($_FILES[$fname]['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
};
[/code]
then see what message it tells you.[code=php]$xpath = "./".uniqid().$xname;[/code]
try just editing that line, for some reason it's unable to move the file, so maybe it's just a problem with the path, if that's not it you may have to look into the permitions of your folder...[code=php]
if(!move_uploaded_file($_FILES[$fname]['tmp_name'], $xpath)){
die("There was an error uploading the file, please try again!");
}; [/code]
[code=php]$xpath ="./upload_".uniqid().basename($_FILES[$upload]['name']);[/code]
0.1.9 — BETA 5.19