Advertisement
michaelyuen

Untitled

Feb 12th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. include "dbcon.php";
  3.  
  4. class file extends database {
  5.     private $extension = ['image/png', 'image/jpeg', 'image/jpg'];
  6.     public function upload($file) {
  7.         if (is_array($file)) {
  8.             if (in_array($file['type'], $this->extension)) {
  9.                 if (move_uploaded_file($file['tmp_name'], 'upload/' . $file['name'])) {
  10.                         // $file is an array not string and it should be $file['name'] instead
  11.                         $sql = "INSERT INTO picture (name) VALUES ('$file')";
  12.                         if ($result = mysqli_query($this->con, $sql)) {
  13.                             die("mysql error: " .mysqli_error($this->con)); // echo your mysql error
  14.                         }
  15.                 } else {
  16.                     die("something is wrong, check file and folder"); // give better description
  17.                 }
  18.             } else {
  19.                 die("wrong file type"); // give better description
  20.             }
  21.         } else {
  22.             die("file is not array"); // give better description
  23.         }
  24.     }
  25. }
  26.  
  27. $fileupload = new file();
  28.  
  29. if (isset($_FILES['file'])) {
  30.     $fileupload->upload($_FILES['file']);
  31. } else {
  32.   die('not submited');
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement