I am trying to code for uploading data from form plus upload file to a server path using PHP. In this I am able to achieve the functionality of uploading files and data but in this I wanted to add one more feature where, if email already exist then a warning should be thrown that "email already exist" and pnly pdf file should be accepted. I tried some coding but it does not work.
Can any guru add code block to the below code to achieve the functionality of unique email id and restrict file type to only pdf.
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-upload']))
{
$name = trim($_POST["uname"]);
$email = trim($_POST["uemail"]);
$exp = trim($_POST["uexp"]);
$desig = trim($_POST["udesig"]);
$tech = trim($_POST["utech"]);
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
// new file size in KB
$new_size = $file_size/1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(name,email,exp,desig,tech,file,type,size) VALUES('$name','$email','$exp','$desig','$tech','$final_file','$file_type','$new_size')";
mysql_query($sql);
?>
<script>
window.location.href='success.php';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='index.php?fail';
</script>
<?php
}
}
?>