Advertisement
Chrizz93

Untitled

Apr 25th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $database = "skp";
  6.  
  7. $conn = new mysqli($servername, $username, $password, $database);
  8.  
  9. if ($conn->connect_error) {    die("Connection failed: " . $conn->connect_error);
  10. }  mysqli_set_charset($conn, "utf8");
  11.  
  12. ?>
  13. <?php
  14. $_FILES['submit']['name'];
  15. $_FILES['submit']['type'];
  16. $_FILES['submit']['size'];
  17. $_FILES['submit']['tmp_name'];
  18.  
  19.  
  20. mysqli_query($conn,"INSERT INTO upload (name,type,size,content) VALUES ('".$_FILES['name']."'".$_FILES['type']."'".$_FILES['size']."'".$_FILES['tmp_name']."')");
  21.  
  22. mysqli_close($conn);
  23.  
  24.  
  25.  
  26. $uploaddir = "upload/";
  27. $uploadfile = $uploaddir . basename($_FILES["submit"]["name"]);
  28. $uploadOk = 1;
  29.  
  30. if (move_uploaded_file($_FILES['submit']['tmp_name'], $uploadfile)) {
  31.     echo "File is valid, and was successfully uploaded.\n";
  32. } else {
  33.     echo "Possible file upload attack!\n";
  34. }
  35.  
  36. echo 'Here is some more debugging info:';
  37. print_r($_FILES);
  38.  
  39. print "</pre>";
  40.  
  41.  
  42. if (file_exists($uploadfile)) {
  43.     echo "Sorry, file already exists.";
  44.     $uploadOk = 0;
  45. }
  46. if ($_FILES["upload"]["size"] > 500000) {
  47.     echo "Sorry, your file is too large.";
  48.     $uploadOk = 0;
  49. }
  50. $f_type = $_FILES['upload']['type'];
  51. if ($f_type== "image/gif" OR $f_type== "image/png" OR $f_type== "image/jpeg" OR $f_type== "image/JPEG" OR $f_type== "image/PNG" OR $f_type== "image/GIF"){
  52. $error=False;
  53. }else{
  54. $error=True;}
  55.  
  56.  
  57. if ($uploadOk == 0) {
  58.     echo "Sorry, your file was not uploaded.";
  59.  
  60. } else {
  61.     if (move_uploaded_file($_FILES["submit"]["tmp_name"], $target_file)) {
  62.         echo "The file ". basename( $_FILES["submit"]["name"]). " has been uploaded.";
  63.     } else {
  64.         echo "Sorry, there was an error uploading your file.";
  65.     }
  66. }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement