How to send input file data value using ajax to a php page

前端 未结 4 1102
有刺的猬
有刺的猬 2020-12-07 04:55

What I want to do is whenever a user selects a picture and click the button it will move the image to a specific folder and save the link to the database user_image column.<

4条回答
  •  死守一世寂寞
    2020-12-07 05:07

        
        
        
        
    
    
    
    
    dbConnect();
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    
    $email = isset($_POST['email']) ? $_POST['email'] : "";
    
    $image = addslashes(file_get_contents($_FILES['file']['tmp_name']));
    $image_name = addslashes($_FILES['file']['name']);
    $image_size = getimagesize($_FILES['file']['tmp_name']);
    
    move_uploaded_file($_FILES["file"]["tmp_name"], "Oppa/upload/" . $_FILES["file"]["name"]);
    $location = "Oppa/upload/" . $_FILES["file"]["name"];
    
    
    if(!empty($_POST['email'])) {
    
            $q = "UPDATE tbl_user SET user_image = '$location' WHERE user_email= :email ";
            $query = $db->prepare($q);
            $query->bindParam(':email', $email);
            $results = $query->execute();
            echo "1";
    }
    
    ?>
    

    don't forget to like my ans :)

提交回复
热议问题