4 Replies Latest reply on Aug 21, 2007 5:30 PM by elechal23

    upload / email form

    elechal23 Level 1
      hello everyone. i made an upload files page with a browse button and text fields for the client to put their information in. how can i make the "submit" button upload the file to my server AND send me the email at the same time?? the uploading part works but not the email part. please help! thanks!!
        • 1. Re: upload / email form
          bregent Most Valuable Participant
          >the uploading part works but not the email part.

          What programming language are you using? Who wrote the scripts?
          • 2. Re: upload / email form
            elechal23 Level 1
            I am using html for the form and php for the actual uploading to work. Here is the form I created:

            <form enctype="multipart/form-data" action="uploader.php" method="POST">
            <span class="style1">
            <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
            <input type="hidden" name="redirect" value="greeny_blu/index.html" />
            </span>
            <table width="565" height="364">
            <tr>
            <td colspan="2"><div align="center" class="style9">
            <div align="left">Upload Files</div>
            </div></td>
            </tr>
            <tr>
            <td colspan="2"><div align="center" class="style10">
            <p align="left">Fill out the form below in order to send us your print-ready files.<br />
            Please make sure to zip or compress your files and do not send any <br />
            files larger than 15mb.</p>
            <p align="left">Thank you for choosing Level Graphics!</p>
            </div></td>
            </tr>
            <tr>
            <td width="148"><label for="companyname">
            <div align="right" class="style20">Company Name:</div>
            </label></td>
            <td width="405"><label for="companyname"></label>
            <input type="text" name="companyname" id="companyname" /></td>
            </tr>
            <tr>
            <td><div align="right" class="style20">Contact Name:</div></td>
            <td><label for="contactname"></label>
            <input type="text" name="contactname" id="contactname" /></td>
            </tr>
            <tr>
            <td><div align="right" class="style20">E-mail Address:</div></td>
            <td><label for="email"></label>
            <input type="text" name="email" id="email" /></td>
            </tr>
            <tr>
            <td><div align="right" class="style20">Telephone Number:</div></td>
            <td><label for="phonenumber"></label>
            <input type="text" name="phonenumber" id="phonenumber" /></td>
            </tr>
            <tr>
            <td><label for="message">
            <div align="right" class="style20">Message:</div>
            </label></td>
            <td><label for="message"></label>
            <textarea name="message" id="message" cols="45" rows="5"></textarea></td>
            </tr>
            <tr>
            <td height="41"><div align="right"><span class="style20">
            <label>
            <label for="upload" class="style10">
            Upload Files:</span></div>
            <div align="center"></div>
            </label></td>
            <td><label for="upload"></label>
            <input name="uploadedfile" type="file" /></td>
            </tr>
            <tr>
            <td colspan="2"><label>
            <div align="center">
            <p align="left" class="style19">When uploading files, do not click the &quot;Upload File&quot; button more than once.<br />
            Please be patient, larger files may take a while to send.</p>
            <p align="left" class="style19">                                      
            <input type="submit" name="submit" id="submit" value="Upload File" />
            </p>
            </div>
            </label></td>
            </tr>
            </table>
            <p class="style1"> </p>
            <span class="style10">By sending us your file you have agreed to our <a href="terms.html">Terms &amp; Conditions </a></span>
            <p class="style10"> </p>
            </FORM>


            I copied the php code from an online tutorial. Here it is:

            // Where the file is going to be placed
            $target_path = "uploads/";

            /* Add the original filename to our target path.
            Result is "uploads/filename.extension" */
            $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
            $_FILES['uploadedfile']['tmp_name'];

            $target_path = "uploads/";

            $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

            if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
            echo "The file ". basename( $_FILES['uploadedfile']['name']).
            " has been uploaded";
            } else{
            echo "There was an error uploading the file, please try again!";
            }

            If you want to view to actual site then go to www.levelgraphics.biz/greeny_blu/upload_files

            Thank you!!!
            • 3. Re: upload / email form
              bregent Most Valuable Participant
              OK, so after the upload section on the php script you just need to add your email processing script.
              • 4. Re: upload / email form
                elechal23 Level 1
                Was I supposed to put both php script in the uploader.php file? Like this?? It did not work =( the uploading part still works but not the email part...please help!!

                <?php
                // Where the file is going to be placed
                $target_path = "uploads/";

                /* Add the original filename to our target path.
                Result is "uploads/filename.extension" */
                $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
                $_FILES['uploadedfile']['tmp_name'];

                $target_path = "uploads/";

                $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

                if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                echo "The file ". basename( $_FILES['uploadedfile']['name']).
                " has been uploaded. Thank you!";
                } else{
                echo "There was an error uploading the file, please try again!";
                }
                ?>

                <?php
                $request_method = $_SERVER["REQUEST_METHOD"];
                if($request_method == "GET"){
                $query_vars = $_GET;
                } elseif ($request_method == "POST"){
                $query_vars = $_POST;
                }
                reset($query_vars);
                $t = date("U");

                $file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
                $fp = fopen($file,"w");
                while (list ($key, $val) = each ($query_vars)) {
                fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
                fputs($fp,"$val\n");
                fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
                if ($key == "redirect") { $landing_page = $val;}
                }
                fclose($fp);
                if ($landing_page != ""){
                header("Location: http://".$_SERVER["HTTP_HOST"
                } else {
                header("Location: http://".$_SERVER["HTTP_HOST"
                }


                ?>