Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
php form script with upload script help
#2
Hey, I combined the script together:

Code:
<html>
<head>
</head>
<body>
<?php
if(! $_POST['submit'])
{
    ?>
<form name="contact" enctype="multipart/form-data" action="contact.php" method="post" onsubmit="return validate_fields(this)">
<div id="form">
<ul>
<li>Name:<br />
<input type="text" size="30" name="name" id="name" /></li>
<li><br /></li>
<li>Location:<br />
<input type="text" name="location" id="location" /></li>
<li><br /></li>
<li>Make:<br />
<input type="text" name="make" id="make" /></li>
<li><br /></li>
<li>Model:<br />
<input type="text" name="model" id="model" /></li>
<li><br /></li>
<li>Referral:<br />
<input type="text" name="referral" id="referral" /></li>
<li><br /></li>
<li><label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
<button>Upload File</button></li>
<li><br /></li>
<li><input type="submit" name="submit" value="Submit" />
&nbsp;
<input type="reset" name="reset" value="Reset" /></li>
</ul>
</div>
<!-- End Contact Form -->
</form>
    <?php
}
else
{
    $company = $_POST["company"];
    $phone = $_POST["phone"];
    $email = $_POST["email"];
    $work = $_POST["work"];
    $page = $_POST["page"];
    $referral= $_POST["referral"];
    $comments = $_POST["comments"];

    $address_to = "removed";
    $address_from = "From: test@test.com";
    $email_subject_line = $company . "'s form";

    $email_text = "Company Name?" . $company .
    "\nPhone number? " . $phone .
    "\nEmail Address? " . $email .
    "\nType of work? " . $work .
    "\nHow many pages? " . $page .
    "\nReferral?" . $referral .
    "\nComments? " . $comments;



    mail($address_to, $email_subject_line, $email_text, $address_from);

    // Configuration - Your Options
          $allowed_filetypes = array('jpg','gif','bmp','png','jpeg','zip',); // These will be the types of file that will pass the validation.
          $max_filesize = 3145728; // Maximum filesize in BYTES (currently 0.5MB).
          $upload_path = './uploads'; // The place the files will be uploaded to (currently a 'files' directory).

       $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
        $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

       // Check if the filetype is allowed, if not DIE and inform the user.
       if(false === in_array(pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION), $allowed_filetypes))
        die('The file you attempted to upload is not allowed.');

       // Now check the filesize, if it is too large then DIE and inform the user.
       if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
          die('The file you attempted to upload is too large.');

       // Check if we can upload to the specified path, if not DIE and inform the user.
       if(!is_writable($upload_path))
          die('You cannot upload to the specified directory, please CHMOD it to 777.');

       // Upload the file to your specified path.
       if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
             echo 'Your file upload was successful, go back to the homepage by clicking <a href="http://www.andrewshemo.com/test/form" title="">here</a>'; // It worked.
          else
             echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
}
?>
</body>
</html>

May I suggest that you take a look at PEAR's email class, It's great for sending email's with attachment's.

http://pear.php.net/packages.php?catpid=14&catname=Mail

Hope I helped you.
Reply


Messages In This Thread
RE: php form script with upload script help - by Cyandelta - 05-05-2010, 10:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 936 07-27-2020, 11:26 PM
Last Post: tk-hassan
  [help] Improve login script Montana" 1 1,728 03-18-2013, 12:59 PM
Last Post: Haxalot
  Req. Upload PHP script. 3 X P L 0 I T 1 1,329 07-14-2012, 05:19 PM
Last Post: 'Snorlax
  PHP email input form - having trouble getting the form to work... abayindi 4 2,722 03-19-2012, 10:02 AM
Last Post: RainbowDashFTW
  [NEED HELP] PHP Form post, get, echo Đενɨаηсε™ 5 2,065 02-06-2012, 01:16 PM
Last Post: ★Cooldude★

Forum Jump:


Users browsing this thread: 2 Guest(s)