Guest User

Untitled

a guest
Nov 2nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. <?php
  2. if(!empty($_FILES)){
  3.  
  4. //database configuration
  5. $dbHost = 'localhost';
  6. $dbUsername = 'root';
  7. $dbPassword = '';
  8. $dbName = 'upload_draganddrop';
  9. //connect with the database
  10. $conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
  11. if($mysqli->connect_errno){
  12. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  13. }
  14.  
  15. $targetDir = "uploads/";
  16. $fileName = $_FILES['file']['name'];
  17. $targetFile = $targetDir.$fileName;
  18.  
  19. if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
  20. //insert file information into db table
  21. $conn->query("INSERT INTO files (file_name, uploaded) VALUES('".$fileName."','".date("Y-m-d H:i:s")."')");
  22. }
  23.  
  24. }
  25. ?>
Add Comment
Please, Sign In to add comment