Jump to content

Upload PDF problem


emediastudios

Recommended Posts

Hi Everyone, I have a small problem and try to learn from all the help i get here.

I have a form that gathers info, emails and inserts info into the database, everything works fine except the file doesnt upload and the file name does not go into the database, instead i get /recruitment in the file field of the databse, instead of recruitment/uploadedfile.pdf

 

Code Below, please help,

 

<?php
switch ($_REQUEST['action']) {
case 'recruit':
foreach($_POST as $key=>$value){
$$key = $value;
}
if ((!$name) || (!$email) || (!$phone)) {
$error_msg = 'Fields marked<span class="gold"> * </span>are required to submit the form';
}elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { 
    $error_msg = 'Invalid email address'; 
}
echo "$error_msg","<br><br>";
if ($error_msg == ''){

$add="recruitment/".$_FILES[userfile][name];
$cleaned = stripit($add);
    $add2 = "../".$cleaned;

    move_uploaded_file ($_FILES[userfile][tmp_name], $add2);		
    $Q = mysql_query("INSERT INTO recruitment (`name`,`phone`,`email`, `qual`,`exper`,`file`) VALUES ('$name','$phone','$email','$qual','$exper','$cleaned')");
  
foreach($_POST as $key=>$value){
$$key = htmlentities(stripslashes($value));
}
$companyname = 'Business college';
$companyemail = '[email protected]';
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$name." <".$email.">\r\n";
$headers .= "Reply-To: ".$name." <".$email.">\r\n";
$to = "".$companyname."<".$companyemail.">";
$subject = "Business College Recruitment Form Submission";
$message = '<style type="text/css>";




<!--
.style {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
    <td class="style">
<b>Details:</b><br /><br />
<b>Name:</b> '.$name.'<br />
<b>Email:</b> '.$email.'<br />
<b>Mobile No:</b> '.$phone.'<br />
<b>Qualifications:</b><br> '.$qual.'<br />
<b>Experience:</b><br /><br />'.$exper.'<br /><br />
<b>Uploaded resume:</b> http://www.mydomain.com.au/'.$cleaned.'
    </td>
  	</tr>
</table>';
mail($to, $subject, $message, $headers);


     
      

echo '<table width="99%" border="0" cellpadding="0" cellspacing="0">

  	<tr>

    <td class="mybody">Hi '.$name.',<p />Thank you for your enquiry. An Consultant will contact you shortly.<br />
      <br />
      </td>
  	</tr>
</table>';

}else{

foreach($_POST as $key=>$value){

$$key = htmlentities(stripslashes($value));

}
echo '
<form id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=recruit">
  <table width="489" border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td width="227">Name:</td>
      <td width="358"><input type="text" name="name" id="name" value="'.$name.'" /></td>
    </tr>
    <tr>
      <td>Contact Mobile:</td>
      <td><input type="text" name="phone" id="phone" value="'.$phone.'" /></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><input type="text" name="email" id="email" value="'.$email.'" /></td>
    </tr>
    <tr>
      <td>Relevent Qualifications:</td>
      <td><textarea name="qual" id="qual" cols="45" rows="5" value="'.$qual.'"></textarea></td>
    </tr>
    <tr>
      <td>Recent Experience:</td>
      <td><textarea name="exper" id="exper" cols="45" rows="5" value="'.$exper.'"></textarea></td>
    </tr>
    <tr>
      <td>Upload Resume:</td>
      <td><input type="file" name="userfile" id="userfile" /></td>
    </tr>
    <tr>
      <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
      <td> </td>
    </tr>
  </table>
</form>';

}

break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/218111-upload-pdf-problem/
Share on other sites

Your <form > tag does not have the necessary enctype= attribute so that uploading a file would work. You php code is also not testing if the upload worked successfully before attempting to access any of the uploaded file information. I recommend reading the upload handling section in the php.net documentation - http://us3.php.net/manual/en/features.file-upload.php

Link to comment
https://forums.phpfreaks.com/topic/218111-upload-pdf-problem/#findComment-1131817
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.