Jump to content

Rename uploaded file


emediastudios

Recommended Posts

Hi everyone, im a newbie and have written this script, has taken me a day to get here. :)

The form inserts data into the database, uploads a file and sends an email.

All this works fine, what i am trying to do is rename the file to the id of the record and check to make sure it is a pdf.

I would really appreciate any help. I've tried and tried and just cant get it to work.

 

<?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 == ''){

$date=date("d/m/y", time());		
$add="recruitment/".$_FILES[userfile][name];
$cleaned = stripit($add);
    $add2 = $cleaned;

   if(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 = 'Mead Business college';
$companyemail = 'ross@emediastudios.com.au';
$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 = "Mead 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 MBC Consultant will contact you shortly.<br />
      <br />
      </td>
  	</tr>
</table>';

}else{

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

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

}
echo '
<FORM ENCTYPE="multipart/form-data" id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=recruit">
  <table width="489" border="0" cellspacing="5" cellpadding="0" class="formsw">
    <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
Share on other sites

Thanks champ, that the pdf issue resolved. As for the rename of the file, i was thinking, rename it to the persons name submitting the pdf, the $name value of the form and put a random number on the end for good measure, or if easier just the id number.

Thanks again for your help

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.