Loading
cannot insert .pdf file to mysql db
  1. if (isset($_POST['submit']))  
  2. {  
  3.      
  4. echo $filename = $_FILES['file1']['name'];  
  5.   
  6.     // destination of the file on the server  
  7.     $destination = 'upload/' . $filename;  
  8.   
  9.     // get the file extension  
  10.     $extension = pathinfo($filename, PATHINFO_EXTENSION);  
  11.   
  12.     // the physical file on a temporary uploads directory on the server  
  13.     $file = $_FILES['file1']['tmp_name'];  
  14.    echo  $size = $_FILES['file1']['size'];  
  15.   
  16.     if (!in_array($extension, ['pdf'])) {  
  17.         echo "You file extension must be .pdf ";  
  18.     } elseif ($_FILES['myfile']['size'] > 1000000) { // file shouldn't be larger than 1Megabyte  
  19.         echo "File too large!";  
  20.     } else {  
  21.         echo 'test';   
  22.         // move the uploaded (temporary) file to the specified destination  
  23.         if (move_uploaded_file($file, $destination))   
  24.         {  
  25.               
  26.             $sql = "INSERT INTO files (id,filename,created) VALUES ('1','$filename', '1')";  
  27.             if (mysqli_query($link, $sql))   
  28.             {  
  29.                 echo "File uploaded successfully";  
  30.             }  
  31.             else   
  32.             {  
  33.                 echo 'Failed to insiert the file.';  
  34.             }  
  35.         } else   
  36.         {  
  37.             echo "Failed to upload file.";  
  38.         }  
  39.     }  
  40. }  
 

4 Replies

Know the answer? Post it — somebody with the same question will find it here.

Sign in to answer this question.