...

View Full Version : attaching file, download link in email script



aarontroy
05-13-2011, 05:01 PM
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.





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.";
}

}



}

tangoforce
05-13-2011, 05:39 PM
Welcome,

Please check out the link in my signature. You've posted quite a lot of code so it's a litle unfair to 'dump n run' without even playing nice ;)

aarontroy
05-13-2011, 05:49 PM
I read all the rules/guidelines and had it wrapped in the
code but when posting it told me to wrap it in [CODE] so i guess i didn't think it wanted to get wrapped in both but just one or the other.

edit: guess it just did need the [php] like i had originally read, knew id mess something up in my first post and get in trouble :) i'm playing nice, haven't used any forums for help just yet so trying to find a home for some possible help.

aarontroy
05-13-2011, 06:02 PM
I think I figured it out..

/**** Have the $msg built after the file and res link has been created ******/


$msg = "From: {$fn} \r\n
Number: {$numb} \r\n
Email: {$email} \r\n
Comment: {$comment} \r\n
Download resume: {$res_link}";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum