i'm fairly new to php and I am trying to wrap up a small project that includes attaching a file to a contact form script. I have gotten it to the point that the contact form will grab the file as well as store the file on the server where I am looking to attach a link to download the file when sending the email out. I'm guessing it's something simple but I am unable to get the link included when submitting the form.
PHP Code:
if(isset($_POST["s"])){
$fn = $_POST["fn"];
$numb = $_POST["numb"];
$email = $_POST["email"];
$comment = $_POST["comment"];
$to = "aaron@pathofwebsite.com";
$subject = "contact form";
$msg = "From: {$fn} \r\n
Number: {$numb} \r\n
Email: {$email} \r\n
Comment: {$comment} \r\n
Download resume: {$res_link}";
//Get the uploaded file information
$name_of_uploaded_file =
basename($_FILES['uploaded_file']['name']);
//get the file extension of the file
$type_of_uploaded_file =
substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file =
$_FILES["uploaded_file"]["size"]/1024;//size in KBs
//Settings
$max_allowed_file_size = 1000; // size in KB
$allowed_extensions = array("doc", "docx", "rtf", "txt", "zip", "rar");
//Validations
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than $max_allowed_file_size";
}
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i<sizeof($allowed_extensions); $i++)
{
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
{
$allowed_ext = true;
}
}
if(!$allowed_ext)
{
$errors .= "\n The uploaded file is not supported file type. ".
" Only the following file types are supported: ".implode(',', $allowed_extensions);
}
//copy the temp. uploaded file to uploads folder
$path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
if(is_uploaded_file($tmp_path))
{
if(!copy($tmp_path, $path_of_uploaded_file))
{
$errors .= '\n error while copying the uploaded file';
}
}
//Build link for the email person where the uploaded file is at
$resume = "http://www.pathofwebsite.com/" . $path_of_uploaded_file;
$res_link = "<a href='$resume'>Download File</a>";
if(empty($email) || empty($numb)){
$msg = "Please enter a phone# or email to contact you at.";
}else{
$number = $fn+$numb;
$send = mail($to, $subject, $msg);
if($send == true){
$msg = "Your email has been sent.";
}else{
$msg = "Seems to be an error, please try sending your message again.";
}
}
}