jjpeacha Posted April 22, 2008 Share Posted April 22, 2008 Hey! Well basicly I have made a contact form for users to apply for a job. I have made a php contact form before with relative ease, however i'm finding it hard to get their CV uploaded and a link put into the email with the form data. I created a script which should send the email and then upload the cv to the server and put a link to it in the email. However I just can't get it to work! Please help. P.S. Just another quick question - say somebody uploaded a file but there was already a file with the same name on the server, will the script give it a temp name? Form Code: <table width="412" height="280" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="410"><form action="job_form.php" method="post" enctype="multipart/form-data" name="jobform"> <p><span class="style3">Work With Us</span></p> <table width="420" border="0" cellspacing="1" cellpadding="3"> <tr> <td width="20%"><div align="right">Name</div></td> <td width="3%">:</td> <td colspan="2"><input name="name" type="text" id="name" size="30" /></td> </tr> <tr> <td><div align="right">Surname</div></td> <td>:</td> <td colspan="2"><input name="surname" type="text" id="surname" size="30" /></td> </tr> <tr> <td><div align="right">Email</div></td> <td>:</td> <td colspan="2"><input name="email" type="text" id="email" size="30" /></td> </tr> <tr> <td><div align="right">Curriculum</div></td> <td>:</td> <td colspan="2"><input type="file" name="cv" id="cv" /></td> </tr> <tr> <td><div align="right">Wanted</div></td> <td>:</td> <td colspan="2"><select name="wanted" id="wanted"> <option value="collaboration">Collaboration</option> <option value="recruitment">Recruitment</option> </select></td> </tr> <tr> <td><div align="right">What are you interested in</div></td> <td>:</td> <td width="39%" align="left" valign="top"><span class="style2"> <label> <input type="checkbox" name="administration" id="administration" /> Administration<br /> <input type="checkbox" name="commercial" id="commercial" /> Commercial<br /> <input type="checkbox" name="lineworker" id="lineworker" /> Line Worker<br /> <input type="checkbox" name="qualityoffice" id="qualityoffice" /> Quality Office<br /> <input type="checkbox" name="miscellaneous" id="miscellaneous" /> Miscellaneous</label> </span></td> <td width="38%" align="left" valign="top"><span class="style2"> <label> <input type="checkbox" name="postsale" id="postsale" /> Post Sale Technical Support</label> <br /> <label> <input type="checkbox" name="warehouse" id="warehouse" /> Warehouse</label> <br /> <label> <input type="checkbox" name="secretary" id="secretary" /> Secretary</label> <br /> <label> <input type="checkbox" name="technicaloffice" id="technicaloffice" /> Technical Office</label> </span></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </form> </td> </tr> </table> job_form.php Code: <?php @$pfw_ip= $_SERVER['REMOTE_ADDR']; @$name = addslashes($_POST['name']); @$surname = addslashes($_POST['surname']); @$email = addslashes($_POST['email']); @$cv_Name = $_FILES['cv']['name']; @$cv_Size = $_FILES['cv']['size']; @$cv_Temp = $_FILES['cv']['tmp_name']; @$cv_Mime_Type = $_FILES['cv']['type']; @$wanted = addslashes($_POST['wanted']); @$administration = addslashes($_POST['administration']); @$commercial = addslashes($_POST['commercial']); @$lineworker = addslashes($_POST['lineworker']); @$qualityoffice = addslashes($_POST['qualityoffice']); @$miscellaneous = addslashes($_POST['miscellaneous']); @$postsale = addslashes($_POST['postsale']); @$warehouse = addslashes($_POST['warehouse']); @$secretary = addslashes($_POST['secretary']); @$technicaloffice = addslashes($_POST['technicaloffice']); function RecursiveMkdir($path) { if (!file_exists($path)) { RecursiveMkdir(dirname($path)); mkdir($path, 0777); } } if (strlen($name) == 0 ) { die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid name</font></p>"); } if (strlen($surname) == 0 ) { die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid surname</font></p>"); } if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email)) { die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid email</font></p>"); } if (strlen($email) == 0 ) { die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid email</font></p>"); } if( $cv_Size == 0) { die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid cv</font></p>"); } if( $cv_Size >2000000) { unlink($cv_Temp); die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid cv</font></p>"); } if( $cv_Mime_Type != "application/msword" AND $cv_Mime_Type != "application/pdf" AND $cv_Mime_Type != "application/rtf" AND $cv_Mime_Type != "application/zip" ) { unlink($cv_Temp); die("<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid cv</font></p>"); } $uploadFile = "../uploads/".$cv_Name ; if (!is_dir(dirname($uploadFile))) { @RecursiveMkdir(dirname($uploadFile)); } else { @chmod(dirname($uploadFile), 0777); } @move_uploaded_file( $cv_Temp , $uploadFile); chmod($uploadFile, 0644); $cv_URL = "http://testdomain.com/uploads/".$cv_Name ; $pfw_header = "From: $email\n" . "Reply-To: $email\n"; $pfw_subject = "Work With Us - RESPONSE"; $pfw_email_to = "[email protected]"; $pfw_message = "Visitor's IP: $pfw_ip\n" . "name: $name\n" . "surname: $surname\n" . "email: $email\n" . "cv: $cv_URL\n" . "wanted: $wanted\n" . "administration: $administration\n" . "commercial: $commercial\n" . "lineworker: $lineworker\n" . "qualityoffice: $qualityoffice\n" . "miscellaneous: $miscellaneous\n" . "postsale: $postsale\n" . "warehouse: $warehouse\n" . "secretary: $secretary\n" . "technicaloffice: $technicaloffice\n"; @mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ; $pfw_header = "From: [email protected]\n" . "Reply-To: [email protected]\n"; $pfw_subject = "Thanks For Applying"; $pfw_email_to = "$email"; $pfw_message = "Thanks for applying to join the test team. We will get in contact with you as soon as possible.\n" . "\n" . "Regards,\n" . "\n" . "test"; @mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ; echo("<p align='center'><font face='Arial' size='3' color='#008000'>Your Application Has Been Recieved.</font></p>"); ?> Link to comment https://forums.phpfreaks.com/topic/102381-contact-form-with-file-upload/ Share on other sites More sharing options...
jjpeacha Posted April 23, 2008 Author Share Posted April 23, 2008 Can anybody help? Link to comment https://forums.phpfreaks.com/topic/102381-contact-form-with-file-upload/#findComment-524696 Share on other sites More sharing options...
dtjester Posted April 23, 2008 Share Posted April 23, 2008 Is the file getting uploaded at all or not? Link to comment https://forums.phpfreaks.com/topic/102381-contact-form-with-file-upload/#findComment-524699 Share on other sites More sharing options...
spillage Posted April 23, 2008 Share Posted April 23, 2008 I am very new to all this coding stuff but am fairly sure if a file is uploaded to your server with the same name the old file will be overwritten. There is a way to attach a randon number to the uploaded file. //This line assigns a random number to a variable. You could also use a timestamp here if you prefer. $ran = rand () ; //This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended. $ran2 = $ran."."; //This assigns the subdirectory you want to save into... make sure it exists! $target = "images/"; //This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext; Just pulled this from google. http://php.about.com/od/advancedphp/ss/rename_upload_3.htm. Hope it helps. Mark Link to comment https://forums.phpfreaks.com/topic/102381-contact-form-with-file-upload/#findComment-524809 Share on other sites More sharing options...
jjpeacha Posted April 23, 2008 Author Share Posted April 23, 2008 Thanks mark i'll give that a go; and no the file isn't getting uploaded. I wrote that script when I was really tired so I'm going to try and re-write it. Ill update you on how its going to go! Link to comment https://forums.phpfreaks.com/topic/102381-contact-form-with-file-upload/#findComment-524963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.