• <legend id='2SZEr'><style id='2SZEr'><dir id='2SZEr'><q id='2SZEr'></q></dir></style></legend>

      <i id='2SZEr'><tr id='2SZEr'><dt id='2SZEr'><q id='2SZEr'><span id='2SZEr'><b id='2SZEr'><form id='2SZEr'><ins id='2SZEr'></ins><ul id='2SZEr'></ul><sub id='2SZEr'></sub></form><legend id='2SZEr'></legend><bdo id='2SZEr'><pre id='2SZEr'><center id='2SZEr'></center></pre></bdo></b><th id='2SZEr'></th></span></q></dt></tr></i><div id='2SZEr'><tfoot id='2SZEr'></tfoot><dl id='2SZEr'><fieldset id='2SZEr'></fieldset></dl></div>
    1. <tfoot id='2SZEr'></tfoot>
        <bdo id='2SZEr'></bdo><ul id='2SZEr'></ul>

        <small id='2SZEr'></small><noframes id='2SZEr'>

        如何使用ajax将输入文件数据值发送到php页面

        时间:2023-10-05
          <tbody id='3kNrI'></tbody>
        <legend id='3kNrI'><style id='3kNrI'><dir id='3kNrI'><q id='3kNrI'></q></dir></style></legend>
        <i id='3kNrI'><tr id='3kNrI'><dt id='3kNrI'><q id='3kNrI'><span id='3kNrI'><b id='3kNrI'><form id='3kNrI'><ins id='3kNrI'></ins><ul id='3kNrI'></ul><sub id='3kNrI'></sub></form><legend id='3kNrI'></legend><bdo id='3kNrI'><pre id='3kNrI'><center id='3kNrI'></center></pre></bdo></b><th id='3kNrI'></th></span></q></dt></tr></i><div id='3kNrI'><tfoot id='3kNrI'></tfoot><dl id='3kNrI'><fieldset id='3kNrI'></fieldset></dl></div>

                <bdo id='3kNrI'></bdo><ul id='3kNrI'></ul>
                • <tfoot id='3kNrI'></tfoot>

                  <small id='3kNrI'></small><noframes id='3kNrI'>

                • 本文介绍了如何使用ajax将输入文件数据值发送到php页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想要做的是每当用户选择图片并单击按钮时,它会将图像移动到特定文件夹并将链接保存到数据库 user_image 列.

                  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.

                  我的问题是在我单击提交按钮后,图片的实际名称没有保存在数据库列中.例子 Oppa/upload/ 即保存在数据库中的值,无图片文件名.

                  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.

                  我认为 photo.php 没有收到文件的值,谁能帮我解决.

                  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>
                  

                  脚本:

                  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;
                  

                  照片.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";
                  }
                  
                  ?>
                  

                  推荐答案

                  看看这个 http://malsup.com/jquery/form/#ajaxSubmit.

                  包含该插件 jquery.form.js 然后试试这个.

                  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");
                              }
                          }
                      });
                  

                  这应该有效.我用它来上传 ajax 图片.

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

                  谢谢.

                  这篇关于如何使用ajax将输入文件数据值发送到php页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:类属性中的 PHP 函数调用 下一篇:计算受 plpgsql 函数影响的行数

                  相关文章

                  最新文章

                • <tfoot id='tAc3P'></tfoot>
                • <i id='tAc3P'><tr id='tAc3P'><dt id='tAc3P'><q id='tAc3P'><span id='tAc3P'><b id='tAc3P'><form id='tAc3P'><ins id='tAc3P'></ins><ul id='tAc3P'></ul><sub id='tAc3P'></sub></form><legend id='tAc3P'></legend><bdo id='tAc3P'><pre id='tAc3P'><center id='tAc3P'></center></pre></bdo></b><th id='tAc3P'></th></span></q></dt></tr></i><div id='tAc3P'><tfoot id='tAc3P'></tfoot><dl id='tAc3P'><fieldset id='tAc3P'></fieldset></dl></div>

                  1. <small id='tAc3P'></small><noframes id='tAc3P'>

                      <bdo id='tAc3P'></bdo><ul id='tAc3P'></ul>
                  2. <legend id='tAc3P'><style id='tAc3P'><dir id='tAc3P'><q id='tAc3P'></q></dir></style></legend>