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

user3842025

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.

My problem is the actual name of the picture is not save in the database column after i click the submit button. example Oppa/upload/ thats the value saved in the database no picture file name.

I think the value of the file didnt receive by photo.php can anyone help me solve it.

<input type='file' id="imageInput" name="imageInput" accept="image/*" />
<button  id="changePicture" name="changePicture">Submit</button>

script:

var data = {};
        data.imageInput = $('#imageInput').val();
        data.email = $('#email').val();

        $.ajax({
            type: "POST",
            url: "Oppa/view/photo.php",
            data: data,
            cache: false,
            success: function (response) {

            if (Number(response) == 1)
                {
                   $("#dialog-confirm-changedImage").dialog("open");
                }
            }
        });
            return false;

photo.php

<?php
include_once('../dbc/database.php');

$db = new Connection();
$db = $db->dbConnect();
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$email = isset($_POST['email']) ? $_POST['email'] : "";

$image = addslashes(file_get_contents($_FILES['imageInput']['tmp_name']));
$image_name = addslashes($_FILES['imageInput']['name']);
$image_size = getimagesize($_FILES['imageInput']['tmp_name']);

move_uploaded_file($_FILES["imageInput"]["tmp_name"], "Oppa/upload/" . $_FILES["imageInput"]["name"]);
$location = "Oppa/upload/" . $_FILES["imageInput"]["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";
}

?>
Siva.G ツ

Take a look at this http://malsup.com/jquery/form/#ajaxSubmit.

Include that plugin jquery.form.js and then try this.

$('#FormID').ajaxSubmit({ //FormID - id of the form.
        type: "POST",
        url: "Oppa/view/photo.php",
        data: $('#FormID').serialize(),
        cache: false,
        success: function (response) {

        if (Number(response) == 1)
            {
               $("#dialog-confirm-changedImage").dialog("open");
            }
        }
    });

This should work. I'm using it for ajax image upload.

Thanks.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to send data from one page to other page in php when the user clicks on the displaying value as said below

분류에서Dev

how do i send file and data using alloy ui ajax call in liferay

분류에서Dev

How to send Json data into database using Jquery and Ajax?

분류에서Dev

How to send on server multiple data using ajax call?

분류에서Dev

how to return an integer value from a php file using ajax method of jquery?

분류에서Dev

Jquery ajax post doesn't send data to server end(Using PHP)

분류에서Dev

Send values from one PHP file to another with JavaScript/AJAX

분류에서Dev

ajax data parameter not retrieved in php file

분류에서Dev

send value on href with ajax using post method on CI

분류에서Dev

Send and receive data using nodejs without displaying it on my page?

분류에서Dev

Using HTML, PHP and Ajax in the same file

분류에서Dev

How to send email with pdf attachment using php?

분류에서Dev

Ajax pass value to other php file and use the value in if statement

분류에서Dev

How to convert a value from a text input into an array for Google Visualization API using PHP?

분류에서Dev

How to send and retrieve cross-domain ajax data in userscript

분류에서Dev

How to show the image uploaded using HTML file control on a new page after form submission in PHP?

분류에서Dev

How to send integer as parameter to servlet using $.ajax get?

분류에서Dev

How to send the session to the next page using XMPP and Strophejs?

분류에서Dev

How to use the data passed with ajax in the php script?

분류에서Dev

How to take value from input and take it to AJAX request link?

분류에서Dev

How to pass form input value from jsp page to java class?

분류에서Dev

Send js variable to a php .ajax

분류에서Dev

Get data value from php array with autocomplete jquery/ajax

분류에서Dev

How to use Asynchronous and onPostExecute to send value to PHP and get Response

분류에서Dev

How to get data param on the destination page from Ajax response call

분류에서Dev

How to Load filtered data with Ajax, without reloading the whole page in laravel

분류에서Dev

IBM worklight - How to send Request Parameters to a PHP file?

분류에서Dev

How to add more pages and send a value in node using express?

분류에서Dev

how to call a variable value in another php file

Related 관련 기사

  1. 1

    How to send data from one page to other page in php when the user clicks on the displaying value as said below

  2. 2

    how do i send file and data using alloy ui ajax call in liferay

  3. 3

    How to send Json data into database using Jquery and Ajax?

  4. 4

    How to send on server multiple data using ajax call?

  5. 5

    how to return an integer value from a php file using ajax method of jquery?

  6. 6

    Jquery ajax post doesn't send data to server end(Using PHP)

  7. 7

    Send values from one PHP file to another with JavaScript/AJAX

  8. 8

    ajax data parameter not retrieved in php file

  9. 9

    send value on href with ajax using post method on CI

  10. 10

    Send and receive data using nodejs without displaying it on my page?

  11. 11

    Using HTML, PHP and Ajax in the same file

  12. 12

    How to send email with pdf attachment using php?

  13. 13

    Ajax pass value to other php file and use the value in if statement

  14. 14

    How to convert a value from a text input into an array for Google Visualization API using PHP?

  15. 15

    How to send and retrieve cross-domain ajax data in userscript

  16. 16

    How to show the image uploaded using HTML file control on a new page after form submission in PHP?

  17. 17

    How to send integer as parameter to servlet using $.ajax get?

  18. 18

    How to send the session to the next page using XMPP and Strophejs?

  19. 19

    How to use the data passed with ajax in the php script?

  20. 20

    How to take value from input and take it to AJAX request link?

  21. 21

    How to pass form input value from jsp page to java class?

  22. 22

    Send js variable to a php .ajax

  23. 23

    Get data value from php array with autocomplete jquery/ajax

  24. 24

    How to use Asynchronous and onPostExecute to send value to PHP and get Response

  25. 25

    How to get data param on the destination page from Ajax response call

  26. 26

    How to Load filtered data with Ajax, without reloading the whole page in laravel

  27. 27

    IBM worklight - How to send Request Parameters to a PHP file?

  28. 28

    How to add more pages and send a value in node using express?

  29. 29

    how to call a variable value in another php file

뜨겁다태그

보관