If you are getting an error: Undefined index: pdf_file
Then follow this steps:
First of all, you need to set enctype in your form tag
enctype="multipart/form-data"
Then set accept in the input file for example:
accept="application/pdf"
When you upload PDF file using PHP then check every position in your code use echo/print_r() what code is returned to you.
Source code:
HTML:
<form method="post" role="form" enctype="multipart/form-data"> <input type="file" name="upload_pdf_file" accept="application/pdf" /> <button type="submit" name="submit" class="btn btn-success">Submit</button> </form>
PHP:
<?php $allowedExts = array("pdf"); $temp = explode(".", $_FILES["upload_pdf_file"]["name"]); $extension = end($temp); $upload_pdf=$_FILES["upload_pdf_file"]["name"]; move_uploaded_file($_FILES["upload_pdf_file"]["tmp_name"],"uploads/pdf/" . $_FILES["upload_pdf_file"]["name"]); $sql=mysqli_query($con,"INSERT INTO `Table Name`(`table field name`)VALUES($upload_pdf')") or die(mysqli_error($con)); if($sql){ echo "Successful"; } else{ echo "Error!!"; } ?>
Hope it will be helpful for you.
Question and answer is powered by AnsPress.io