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";
}
?>
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] 삭제
몇 마디 만하겠습니다