I want to develop an apply online for a job feature. I have written the following code to upload a resume, but if the user clicks "apply" he will want to send uploaded resume as an email attachment. I am using phpmailer and have sucessfully gotten to send email, but it doesn't have the file attached.
Here is my code to upload a file:
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$connect=mysql_connect("localhost","root","") or die("Couldnt connect");
mysql_select_db("dbname") or die("Couldnt DB");
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
$uploads_dir = 'uploads/';
move_uploaded_file($tmpName, "$uploads_dir/$fileName");
}
And this is PHPmailer code:
$mail->AddAttachment("uploads"."/".$fileName);
I have created "uploads" folder and I am getting all uploaded files therein. But I'm not getting the file uploaded as an email attachment.