Jump to content

Form Code Help


wero86

Recommended Posts

Hey guy need some help with this code!

 

<?php
// Receiving variables
$Name = addslashes($_POST['Name']);
$Email = addslashes($_POST['Email']);
$Tel = addslashes($_POST['Tel']);
$JobCV_Name = $_FILES['JobCV']['name'];
$JobCV_Size = $_FILES['JobCV']['size'];
$JobCV_Temp = $_FILES['JobCV']['tmp_name'];
$JobCV_Mime_Type = $_FILES['JobCV']['type'];
$Validation = 1;

function RecursiveMkdir($path)
{
   if (!file_exists($path)) 
   { 
      RecursiveMkdir(dirname($path));
      mkdir($path, 0777);
    }
  }


// Validation
if (strlen($Name) == 0 )
{
echo "Your Must enter a name.<br>"; 
$Validation=0; 
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $Email))
{
echo "Your Must enter a valid email.<br>"; 
$Validation=0;
}

if (strlen($Email) == 0 )
{
echo "Your Must enter a email.<br>"; 
$Validation=0;
}

if ( $Tel <= 0)
{
echo "Your Must enter a valid telephone number .<br>"; 
$Validation=0;
}

if (strlen($Tel) == 0 )
{
echo "Your Must enter a telephone number.<br>"; 
$Validation=0;
}

if( $JobCV_Size == 0)
{
echo "Your Must upload a CV.<br>"; 
$Validation=0;
}
if( $JobCV_Size >35000000)
{
//delete file 
unlink($JobCV_Temp);
echo "Your file was too large.<br>"; 
$Validation=0;
}
if( $JobCV_Mime_Type != "application/msword" )
{
unlink($JobCV_Temp);
echo "You can only upload a microsoft word document.<br>"; 
$Validation=0;
}
if ($Validation==0) 
{ 
Echo "Sorry your file was not uploaded press back and try again"; 
} 
else
{
$uploadFile = "Uploads/".$JobCV_Name ;
if (!is_dir(dirname($uploadFile)))
  {
    @RecursiveMkdir(dirname($uploadFile)); 
  }
else
  {
  @chmod(dirname($uploadFile), 0777);
  }
@move_uploaded_file( $JobCV_Temp , $uploadFile); 
chmod($uploadFile, 0644);
$JobCV_URL = "http://www.........................co.uk/pages/Uploads/".$JobCV_Name ;

//Sending Email to form owner
$pfw_header = "From: $Email\n"
  . "Reply-To: $Email\n";
$pfw_subject = "Job Application";
$pfw_email_to = "[email protected]";
$pfw_message = "Name: $Name\n"
. "Email: $Email\n"
. "Tel: $Tel\n"
. "JobCV: $JobCV_URL\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
$pfw_subject = "Job Application";
$pfw_email_to = "$Email";
$pfw_message = "We receved your CV";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record in a text file
$pfw_file_name = "Jobs.csv";
$pfw_first_raw = "Name,Email,Tel,JobCV\r\n";
$pfw_values = "$Name,$Email,$Tel,$JobCV_Name\r\n";
$pfw_is_first_row = false;
if(!file_exists($pfw_file_name))
{
$pfw_is_first_row = true ;
}
if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {
die("Cannot open file ($pfw_file_name)");
exit;
}
if ($pfw_is_first_row)
{
  if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {
  die("Cannot write to file ($pfw_filename)");
  exit;
  }
}
if (fwrite($pfw_handle, $pfw_values) === FALSE) {
  die("Cannot write to file ($pfw_filename)");
  exit;
}
fclose($pfw_handle);

header("Location: ThankYouJobs.html");
}
?>

 

The part that is causing the issue is

 

if( $JobCV_Mime_Type != "application/msword" )
{
unlink($JobCV_Temp);
echo "You can only upload a microsoft word document.<br>"; 
$Validation=0;

 

The problem being that it doesnt let me upload a microsoft word document!!!! when i remove this if statment it works fine! also on a side issue at the min the errors come up on a seperate page is there any way of getting them to some up on the actuall form page????? the code for the form is

 

<form action="jobs.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
            <table width="483" border="0">
              <tr>
                <td width="66" align="right">Name:</td>
                <td width="407"><label>
                  <input name="Name" type="text" id="Name" accesskey="1" tabindex="1" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right">Email:</td>
                <td><label>
                  <input name="Email" type="text" id="Email" accesskey="2" tabindex="2" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right">Tel:</td>
                <td><label>
                  <input name="Tel" type="text" id="Tel" accesskey="3" tabindex="3" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right">CV:</td>
                <td><label>
                  <input name="JobCV" type="file" id="JobCV" accesskey="4" tabindex="4" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right"> </td>
                <td><label>
                  <input name="Submit" type="submit" id="Submit" accesskey="5" tabindex="5" onclick="MM_validateForm('Name','','R','Email','','RisEmail','Tel','','RisNum');return document.MM_returnValue" value="send" />
                </label>
                  <label>
                    <input type="reset" name="Reset" id="Reset" value="Clear" accesskey="6" tabindex="6" />
                  </label></td>
              </tr>
            </table>
          </form>

 

any help would be gr8

Link to comment
https://forums.phpfreaks.com/topic/156947-form-code-help/
Share on other sites

try "application/octet-stream" instead of "application/msword"

 

if that doesn't do it, read up on the different MIME types for word docs, you'll find your answer

 

 

EDIT:  Also, try sticking something like:  echo  $JobCV_Mime_Type; into your code and upload a file you know to be a word doc then see what specific mime type is echoed out.  That'll help diagnose the problem.

Link to comment
https://forums.phpfreaks.com/topic/156947-form-code-help/#findComment-826737
Share on other sites

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.