Please what is wrong with this image upload code?

images php coding issues or problems here.

Moderators: macek, egami, gesf

ola1961
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Mar 10, 2011 9:36 am

Please what is wrong with this image upload code?

Postby ola1961 » Thu Mar 10, 2011 2:40 pm

Hello all,

I am a real novice to PHP Scripting. However I got a script to use on my website for creating form and uploading images to my email.

Basically, what I want to happen is for people to get to the site, click on a link, and it takes them to a page where they fill the form and at the end, browse for an image on their computer, upload the image and then submit. The submission is to go to my existing email address.

However, from tweaking the script for about two weeks now, all I get is data without the image. When I tested it, I can fill the form very well, when I browse to the picture I get to that point as well, but when I click upload, the form submits without attaching the image. When I check the email, the data is there but no image.

So the problem is that I am thinking that I am almost there, but the image not attaching is killing me,

Can somone please put me out of my misery?

The PHP Script that I am using is here: It is followed by the html file that I use with it. Hope this is not too much info.


<?php
$my_email = "data@safenigerianhomes.com";
continue = "index.html";
// This line prevents values being entered in a URL
if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}
// Describe function to check for new lines.
function new_line_check($a)
{
if(preg_match('`[\r\n]`',$a)){header("location: $_SERVER[HTTP_REFERER]");exit;}
}
new_line_check($_POST['Name']);
// Check for disallowed characters in the Name and Email fields.
$disallowed_name = array(':',';','"','=','(',')','{','}','@');
foreach($disallowed_name as $value)
{
if(stristr($_POST['Name'],$value)){header("location: $_SERVER[HTTP_REFERER]");exit;}
}
new_line_check($_POST['Email']);
$disallowed_email = array(':',';',"'",'"','=','(',')','{','}');
foreach($disallowed_email as $value)
{
if(stristr($_POST['Email'],$value)){header("location: $_SERVER[HTTP_REFERER]");exit;}
}
$message = "";
// This line prevents a blank form being sent, and builds the message.
foreach($_POST as $key => $value){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}
$message = $message . "-- \nThank you for Filling The Form from http://safenigerianhomes.com";
$message = stripslashes($message);
$subject = "Data Form";
$headers = "From: " . $_POST['Email'] . "\n" . "Return-Path: " . $_POST['Email'] . "\n" . "Reply-To: " . $_POST['Email'] . "\n";
mail($my_email,$subject,$message,$headers);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Safe Nigerian Homes</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-uk">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="arial">
<object><center>
<h1>Thank you <?php print stripslashes($_POST['Name']); ?>!</h1>
<h2>Your form has been received</h2>
<h3><a href="<?php print "$continue"; ?>">Click here to go back to Home Page</a></h3>
</center></object>

</font>

</body>
</html>


I am using the above in conjunction with an html file:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Safe Nigerian Homes</title>
<style type="text/css">


a:link {
   color: #000099;
   text-decoration: none;
}
a:visited {
   text-decoration: none;
   color: #CCFF33;
}
a:hover {
   text-decoration: underline;
   color: #009933;
}
a:active {
   text-decoration: none;
   color: #CCFFCC;
}
.style1 {
   font-family: "Myriad Web";
   font-size: medium;
}td img {display: block;}
body {
   margin-left: 0px;
   margin-top: 0px;
   margin-right: 0px;
   margin-bottom: 0px;
}
.style2 {font-family: "Myriad Web"}
.style3 {font-size: medium}td img {display: block;}
.style6 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style8 {   font-family: Calibri;
   font-size: small;
}
.style9 {font-family: Geneva, Arial, Helvetica, sans-serif}
.style12 {font-family: Calibri; font-size: medium; }
.style13 {font-family: Calibri}
.style15 {font-size: xx-large; font-weight: bold; font-family: Calibri; }
.style16 {font-size: xx-large; font-style: italic; font-family: Calibri; }
</style></head>

<body>

<div align="center">
  <table width="1000" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    <!--DWLayoutTable-->
    <tr>
      <td height="19" colspan="5" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td width="200" rowspan="6" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="200" height="600" valign="top"><div align="center">
              <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p class="style15">Looking For<br />
                  Traffic?</p>
                <p class="style16">Then Place</p>
                <p class="style16">your</p>
                <p class="style15">AD</p>
                <p class="style16">HERE</p>
                <p class="style7">&nbsp;</p>
                </div></td>
          </tr>
         
         
         
      </table></td>
    </tr>
    <tr>
      <td height="12" colspan="4" valign="top" bgcolor="#FFFFFF"><div align="right">
          <table border="0" cellpadding="0" cellspacing="0" width="146">
            <!-- fwtable fwsrc="link_uper.png" fwbase="link_uper.jpg" fwstyle="Dreamweaver" fwdocid = "1271440546" fwnested="0" -->
            <tr>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="3" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="36" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="4" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="48" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="3" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="49" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="3" height="1" border="0" id="undefined_2" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="1" height="1" border="0" id="undefined_2" /></td>
            </tr>
            <tr>
              <td><img name="link_uper_r1_c1" src="link_uper_r1_c1.jpg" width="3" height="11" border="0" id="link_uper_r1_c1" alt="" /></td>
              <td><a href="index.html"><img name="link_uper_r1_c2" src="link_uper_r1_c2.jpg" width="36" height="11" border="0" id="link_uper_r1_c2" alt="" /></a></td>
              <td><img name="link_uper_r1_c3" src="link_uper_r1_c3.jpg" width="4" height="11" border="0" id="link_uper_r1_c3" alt="" /></td>
              <td><a href="contact.html"><img name="link_uper_r1_c4" src="link_uper_r1_c4.jpg" width="48" height="11" border="0" id="link_uper_r1_c4" alt="" /></a></td>
              <td><img name="link_uper_r1_c5" src="link_uper_r1_c5.jpg" width="3" height="11" border="0" id="link_uper_r1_c5" alt="" /></td>
              <td><img name="link_uper_r1_c6" src="link_uper_r1_c6.jpg" width="49" height="11" border="0" id="link_uper_r1_c6" alt="" /></td>
              <td><img name="link_uper_r1_c7" src="link_uper_r1_c7.jpg" width="3" height="11" border="0" id="link_uper_r1_c7" alt="" /></td>
              <td><img src="spacer.gif" alt="" name="undefined_2" width="1" height="11" border="0" id="undefined_2" /></td>
            </tr>
          </table>
      </div></td>
      <td width="31"></td>
    </tr>
    <tr>
      <td width="20" height="11"></td>
      <td width="10"></td>
      <td width="520"></td>
      <td width="219"></td>
      <td></td>
    </tr>
    <tr>
      <td height="55" colspan="5" valign="top" bgcolor="#FFFFFF"><div align="center"><img src="care.gif" width="800" height="55" /></div></td>
    </tr>
     
    <tr>
      <td rowspan="2" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td height="588" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <!--DWLayoutTable-->
          <tr>
            <td width="14" height="576"></td>
            <td width="31">&nbsp;</td>
            <td width="411" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
              <!--DWLayoutTable-->
              <tr>
                <td width="411" height="40" valign="top"><div align="left"></div></td>
                </tr>
              <tr>
                <td height="519" valign="top"><div align="left">
                  <form method="POST" name="email_form_with_php" action="upload_data.php" enctype="multipart/form-data">
                    <table width="370">
                      <tr>
                        <td width="362"><div align="left" class="style13">Employer Name:</div></td>
                          </tr>
                      <tr>
                        <td><div align="left" class="style13">
                          <label>
                            <input type="text" name="textfield" />
                            </label>
                          </div></td>
                          </tr>
                      <tr>
                        <td class="style13"><div align="left">Employer Phone Number:</div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label>
                          <input type="text" name="textfield2" />
                          </label>
                          </div></td>
                          </tr>
                      <tr>
                        <td><div align="left"><span class="style13">Employee Name:</span></div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <label>
                          <input type="text" name="textfield72" />
                          </label>
</div></td>
                          </tr>
                      <tr>
                        <td height="21"><div align="left"><span class="style13">Employee Address:</span></div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <label>
                          <input type="text" name="textfield7" />
                          </label>
</div></td>
                      </tr>
                      <tr>
                        <td><div align="left"><span class="style13">Employee Start Date:</span></div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <label></label>
                          <span class="style13">
                          <label></label>
                          </span>
                          <label>
                          <input type="text" name="textfield3" />
                          </label>
                          <span class="style13">mm/dd/yyyy</span></div></td>
                          </tr>
                      <tr>
                        <td><div align="left" class="style13">
                          <label></label>
                        Employee Position:</div></td>
                          </tr>
                      <tr>
                        <td><div align="left" class="style13">
                          <label>
                          <select name="select" id="select">
                            <option>Cook</option>
                            <option>Driver</option>
                            <option>Gardener</option>
                            <option>Maid</option>
                            <option>Nanny</option>
                            <option>Security Guard</option>
                            <option>Washerman</option>
                          </select>
                          </label>
</div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <span class="style13">Discerning Physical Characteristic</span><span class="style13">s:
                          <label></label>
                          </span>
                          <label></label>
                        </div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <label>
                          <input type="text" name="textfield4" />
                          </label>
                        </div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <label></label>
                          <span class="style13">Comment on Employee to Date:</span></div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label>
                          <textarea name="textarea"></textarea>
                          </label>
</div></td>
                          </tr>
                      <tr>
                        <td><div align="left"><span class="style13">Is Employee Eligible for re-hire</span>?</div></td>
                          </tr>
                      <tr>
                        <td><div align="left">
                          <label></label>
                          <span class="style13">Yes
                          <label>
                          <input type="checkbox" name="checkbox" value="checkbox" />
                          </label>
| No</span>
                          <label>
                          <input type="checkbox" name="checkbox2" value="checkbox" />
                          </label>
</div></td>
                          </tr>
                      <tr>
                        <td height="27"><label></label>
                          <div align="left">
                            <label></label>
                            <label></label>
                            <span class="style13">Upload your Employee's Picture</span>:</div></td>
                          </tr>
                      <tr>
                        <td height="26"><div align="left">
                          <label></label>
                          <label>
                          <input name="uploaded" type="file" /><br />
                          </label>
                          <label>
                          <input type="submit" name="Upload" value="Upload" />
                          </label>
                        </div></td>
                      </tr>
                      <tr>
                        <td height="26"><div align="left">
                          <label>
                          <input type="submit" name="Submit2" value="Submit" />
                          </label>
                        </div></td>
                      </tr>
                      </table>
                      </form>
                  </div></td>
                </tr>
              <tr>
                <td height="17"></td>
                </tr>
             
             
             
             
             
             
             
             
             
             
            </table></td>
            <td width="74">&nbsp;</td>
          </tr>
          <tr>
            <td height="27"></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
         
         
         
         
         
         
         
          <tr>
            <td height="38">&nbsp;</td>
            <td colspan="3" valign="top"><div align="left" class="style1 style13">
              <div align="center">All information provided on this site will be kept
                Confidential. Thank you. Managment.</div>
            </div></td>
          </tr>
          <tr>
            <td height="73">&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

         
         
         
         
         
         
         
         
      </table></td>
      <td colspan="2" rowspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="250" height="564" valign="top" bgcolor="#C76500"><div align="center">
              <p class="style3"><a href="profile.html/news" class="style1"><br />
                </a></p>
                <p><br />
                  <img src="link.jpg" width="176" height="361" border="0" usemap="#Map" /><br />
                </p>
            </div></td>
          </tr>
         
         
         
         
         
         
         
      </table></td>
    </tr>
     
    <tr>
      <td height="16"></td>
      <td valign="top"><div align="left"><span class="style8">&copy; 2009 Safe Nigerian Homes. All right reserved. </span></div></td>
    </tr>
    <tr>
      <td height="0"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </table>
</div>
  <map name="Map" id="Map">
  <area shape="rect" coords="-6,7,174,39" href="about_us.html" />
<area shape="rect" coords="1,46,172,77" href="our_aims.html" />
<area shape="rect" coords="0,87,180,118" href="domestic.html" />
<area shape="rect" coords="1,128,174,156" href="cooks.html" />
<area shape="rect" coords="0,158,175,187" href="driver.html" />
<area shape="rect" coords="1,188,174,215" href="gardener.html" />
<area shape="rect" coords="-2,217,174,245" href="maids.html" />
<area shape="rect" coords="-1,247,173,276" href="nannies.html" />
<area shape="rect" coords="2,277,173,305" href="guards.html" />
<area shape="rect" coords="1,306,174,333" href="washermen.html" />
<area shape="rect" coords="-1,337,196,382" href="upload_data.html" />
</map>
</body>
</html>


Thanks in advance,

Ola

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Please what is wrong with this image upload code?

Postby johnj » Sun Mar 13, 2011 9:24 pm

You cannot have this line, continue = "index.html";

'continue' has to be $continue or some data type acceptable to php

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Please what is wrong with this image upload code?

Postby johnj » Sun Mar 13, 2011 9:31 pm

In your code there is no action to handle the uploaded image, you need to write code for that. You need to tell php what code to execute when a user clicks 'upload' and inside that upload code you need to tell what to do with the uploaded image file.


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest