PHP tot MySQL image uploading not working

前端 未结 2 744
小蘑菇
小蘑菇 2021-01-26 12:50

I\'m trying to make a site in which I can upload a file to my sql database, but it does not seem to work.

This is my code;


    
         


        
2条回答
  •  长情又很酷
    2021-01-26 13:25

    I hope this helps you:

    
            
                    Upload an image
            
            
        
  • '.$error.'/li>
'; } if($_POST) { //Connecting to the database $connect = mysqli_connect("localhost", "root" ,"", "picturedatabase"); $name = $_FILES['Image']['name']; if(!empty($name)) { $tmp = $_FILES['Image']['tmp_name']; $type = $_FILES['Image']['type']; $allowed_type = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png'); if(!in_array($type, $allowed_type)) { $error[] = $type. ' is not allowed file type'; } } else { $error[] = 'There are empty fields'; } if(!empty($error)) { echo output_errors($error); } else if(empty($error)){ $path = 'images/'.$name; $query = mysqli_query($connect, "INSERT INTO `images` (`image`) VALUES ('$path')"); if(!$query) { echo 'Insert into db went wrong'; } else { move_uploaded_file($tmp, $path); echo 'Upload succesful'; } } } ?>
File:

提交回复
热议问题