Hi,
I tried to insert pdf file to database actually the file uploaded into the folder name 'upload ' but cannot insert into database.
Anyone can help me to clear this issue.
- <div class="row">
- <div class="col-xs-8 col-xs-offset-2 well">
- <form method="post" enctype="multipart/form-data">
- <legend>Select File to Upload:</legend>
- <div class="form-group">
- <input type="file" name="file1" />
- </div>
- <div class="form-group">
- <input type="submit" name="submit" value="Upload" class="btn btn-info"/>
- </div>
-
- </form>
- </div>
- </div>
- if (isset($_POST['submit']))
- {
-
- echo $filename = $_FILES['file1']['name'];
-
-
- $destination = 'upload/' . $filename;
-
-
- $extension = pathinfo($filename, PATHINFO_EXTENSION);
-
-
- $file = $_FILES['file1']['tmp_name'];
- echo $size = $_FILES['file1']['size'];
-
- if (!in_array($extension, ['pdf'])) {
- echo "You file extension must be .pdf ";
- } elseif ($_FILES['myfile']['size'] > 1000000) {
- echo "File too large!";
- } else {
- echo 'test';
-
- if (move_uploaded_file($file, $destination))
- {
-
- $sql = "INSERT INTO files (id,filename,created) VALUES ('1','$filename', '1')";
- if (mysqli_query($link, $sql))
- {
- echo "File uploaded successfully";
- }
- else
- {
- echo 'Failed to insiert the file.';
- }
- } else
- {
- echo "Failed to upload file.";
- }
- }
- }