Page 1 of 1

Form Upload CV Page

Posted: Tue May 05, 2009 10:10 am
by wero86
Hey guy need some help with this code!

Code: Select all

<?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 = "...@..........co.uk";
$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: ......@........co.uk\n"
  . "Reply-To: .....@..........co.uk\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

Code: Select all

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

Code: Select all

<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">&nbsp;</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

Re: Form Upload CV Page

Posted: Wed May 06, 2009 3:56 pm
by david64
I have built a form development framework that would do this for you automatically with the following code:

Code: Select all

<input type="file" name="cv">
<xfl:file type="mime" value="application/msword" error="CV must be a Word Document" />
</input>
You could also accept multiple mime types like this:

Code: Select all

<input type="file" name="cv">
<xfl:file type="mime" error="CV must be a Word document or PDF">
<xfl:value>application/msword</xfl:value>
<xfl:value>application/pdf</xfl:value>
</xfl:file>
</input>
You can find the project page here:

http://semlabs.co.uk/products/xfl

Documentation here: http://semlabs.co.uk/docs/xfl

And an example form using file upload here:

http://semlabs.co.uk/products/xfl/demos/h

If you download the package, there is example code which you should be able to edit to test out what you need to do.