Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "dbcon.php";
- class file extends database {
- private $extension = ['image/png', 'image/jpeg', 'image/jpg'];
- public function upload($file) {
- if (is_array($file)) {
- if (in_array($file['type'], $this->extension)) {
- if (move_uploaded_file($file['tmp_name'], 'upload/' . $file['name'])) {
- // $file is an array not string and it should be $file['name'] instead
- $sql = "INSERT INTO picture (name) VALUES ('$file')";
- if ($result = mysqli_query($this->con, $sql)) {
- die("mysql error: " .mysqli_error($this->con)); // echo your mysql error
- }
- } else {
- die("something is wrong, check file and folder"); // give better description
- }
- } else {
- die("wrong file type"); // give better description
- }
- } else {
- die("file is not array"); // give better description
- }
- }
- }
- $fileupload = new file();
- if (isset($_FILES['file'])) {
- $fileupload->upload($_FILES['file']);
- } else {
- die('not submited');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement