Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    attaching file, download link in email script

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

                
        
            } 
    Last edited by aarontroy; 05-13-2011 at 05:51 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    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
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    aarontroy (05-13-2011)

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    Last edited by aarontroy; 05-13-2011 at 05:54 PM.

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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}";


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •