Jump to content

Problem integrating an upload script with a contact script


skot

Recommended Posts

Hi

 

I have two seperate php files that work fine on their own; One uploads a file to my server, the other sends an email containing data from a form. I'm now trying to integrate them so that when a file is uploaded an email is sent to notify our support team of the details. The file is uploaded fine with no errors, but the only output I get from the resulting email is the target directory of the file; the customers name, company, email and additional info box are not pulled through at all.

 

Could someone please tell me where i'm going wrong?

 

Many Thanks,

Scott

 

Code:

<?php
/*************************************************
* Max's File Uploader
*
* Version: 1.0
* Date: 2007-11-26
*
****************************************************/
class maxUpload{
    var $uploadLocation;
    
    /**
     * Constructor to initialize class varaibles
     * The uploadLocation will be set to the actual 
     * working directory
     *
     * @return maxUpload
     */
    function maxUpload(){
        $this->uploadLocation = getcwd().DIRECTORY_SEPARATOR;
    }

    /**
     * This function sets the directory where to upload the file
     * In case of Windows server use the form: c:\\temp\\
     * In case of Unix server use the form: /tmp/
     *
     * @param String Directory where to store the files
     */
    function setUploadLocation($dir){
        $this->uploadLocation = $dir;
    }
    
    function showUploadForm($msg='',$error=''){
?>

<link href="style_dropbox.css" rel="stylesheet" type="text/css" />

       <style type="text/css">
<!--
.style1 {
font-size: 1.2em;
font-weight: bold;
}
.style2 {font-size: 1.2em}
.style3 {
font-size: 1.2em;
font-style: italic;
color: #000000;
}
.style8 {font-size: 12px; font-weight: bold; }
.style9 {
font-size: 12px;
color: #00846C;
}
.style10 {color: #CC0000}
.style11 {font-size: 12px}
body {
background-color: #FAFBFC;
}
-->
       </style>
       <title>Century Software - Data Upload</title>
       <p align="justify" class="style2">This facility can be used to send information or data to us. Click 'browse' and locate your file then click the 'upload' button. Your file will begin uploading to the server immediatly and a confirmation message will appear once the file has been received successfully.</p>
       <p align="left" class="style3"><strong>Note:</strong> If you are attempting to upload a large file or multiple files at once, please first zip them up.</p>
       <p class="style9">
         <?php
if ($msg != ''){
    echo '<p class="msg"><img src=http://centurysoftware.co.uk/img/y.gif> '.$msg.'</p>';
} else if ($error != ''){
    echo '<p class="emsg"><img src=http://centurysoftware.co.uk/img/n.gif> '.$error.'</p>';

}
?>
       </p>
       <form action="" method="post" enctype="multipart/form-data" name="uploader" id="uploader" >
         <center>
           <label>
           <span class="style8">Your Full Name: 
             <input name="name" type="text" class="style9" id="name" size="50" maxlength="50" />
           <br />  
             
           Your Company: 
           <input name="company" type="text" class="style9" id="company" size="50" maxlength="70" />
           <br />
           
           Your Email Address:
           <input name="email" type="text" class="style9" id="email" size="50" maxlength="70" />
           <br />
           Browse to your file:</span>
           <input name="myfile" type="file" class="style9" size="60" />
           <br />  
           <br />  
           <strong>Additional Information:</strong> <br />  
           <textarea name="info" cols="80" rows="2" id="info"></textarea>
             </label>
             <label>
<div align="center">
             <input type="submit" name="submitBtn" class="pincodebox" value="          Upload File          " />
           </div>
           </center>
       </form>
       <p class="style10 style11"> <br />
           <br />
           <?php
    }

    function uploadFile(){
        if (!isset($_POST['submitBtn'])){
            $this->showUploadForm();
		@extract($_POST);

$name = stripslashes($name);

$company = stripslashes($company);

$email = stripslashes($email);

$info = stripslashes($info);
        } else {
            $msg = '';
            $error = '';
            
            //Check destination directory
            if (!file_exists($this->uploadLocation)){
                $error = "<img src=http://centurysoftware.co.uk/img/n.gif> The target directory doesn't exist! Please notify [email protected]";
            } else if (!is_writeable($this->uploadLocation)) {
                $error = "<img src=http://centurysoftware.co.uk/img/n.gif> The target directory is not writeable! Please notify [email protected]";
            } else {
                $target_path = $this->uploadLocation . basename( $_FILES['myfile']['name']);

                if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
                    $msg = basename( $_FILES['myfile']['name']).
                    " was uploaded successfully! <img src=http://centurysoftware.co.uk/img/y.gif>";
				mail('[email protected]','Data Recieved From Website',"Name: $name \nCompany: $company \nTheir Email: $email \n\nAdditional Info:\n $info \n\nFile: $target_path","From: CenturySoftware.co.uk <[email protected]>") or die("Unable to notify Century Software of your upload.");
                } else{
                    $error = "<img src=http://centurysoftware.co.uk/img/n.gif> The upload process failed! Please try again.";
                }
            }

            $this->showUploadForm($msg,$error);
        }

    }

}
?>
       </p>
       

 

Email Output:

Name:  
Company:  
Their Email:  

Additional Info:
  

File: /home/bridgey/public_html/century/Server Data Report.pdf

Your other variables ($name, $company, $email, $info) are simply not being set....

 

You I can't seem to find any code whith deals with $_POST['name'], $_POST['company'], $_POST['email'] and $_POST['info'] - so try this:

 

<?php
$name = stripslashes($_POST['name']);

$company = stripslashes($_POST['company']);

$email = stripslashes($_POST['email']);

$info = stripslashes($_POST['info']);
?>

Thanks for your reply.

 

I have tried the following and the information isn't coming through to the email still:

 

<?php
$name = stripslashes($_POST['name']);

$company = stripslashes($_POST['company']);

$email = stripslashes($_POST['email']);

$info = stripslashes($_POST['info']);
?>

 

and..

 

           <?php
    }

    function uploadFile(){
        if (!isset($_POST['submitBtn'])){
            $this->showUploadForm();
		@extract($_POST);

		$name = stripslashes($_POST['name']);

		$company = stripslashes($_POST['company']);

		$email = stripslashes($_POST['email']);

		$info = stripslashes($_POST['info']);
		} else {
...

Have also tried this - no change to output:

 

           <?php
	   
        if (!isset($_POST['submitBtn'])){

	@extract($_POST);

	$name = stripslashes($_POST['name']);

	$company = stripslashes($_POST['company']);

	$email = stripslashes($_POST['email']);

	$info = stripslashes($_POST['info']);

	}

?>		   

But they variables will not set if you $_POST['submitBtn'] is set, which it will be if you press the submit button.

 

Try to echo the variables when appropriate and play around with the if statement until you get it right :)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.