Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-13-2011, 04:01 PM   PM User | #1
aarontroy
New to the CF scene

 
Join Date: May 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
aarontroy is an unknown quantity at this point
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 04:51 PM..
aarontroy is offline   Reply With Quote
Old 05-13-2011, 04:39 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,665
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
aarontroy (05-13-2011)
Old 05-13-2011, 04:49 PM   PM User | #3
aarontroy
New to the CF scene

 
Join Date: May 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
aarontroy is an unknown quantity at this point
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 04:54 PM..
aarontroy is offline   Reply With Quote
Old 05-13-2011, 05:02 PM   PM User | #4
aarontroy
New to the CF scene

 
Join Date: May 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
aarontroy is an unknown quantity at this point
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}";
aarontroy is offline   Reply With Quote
Reply

Bookmarks

Tags
attach, contact, email, file, script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:44 AM.


Advertisement
Log in to turn off these ads.