How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.

 

How to upload files and input fields in php with using ajax. How to upload files and input fields in php with using ajax. How to upload files and input fields in php with using ajax.

How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.How to upload files and input fields in php with using ajax.


<!DOCTYPE html>

<html>

<body>


<h1>jQuery Ajax submit Multipart form</h1>


<form method="POST" enctype="multipart/form-data" id="fileUploadForm">

    <input type="text" name="extraField"/><br/><br/>

    <input type="file" name="files"/><br/><br/>

    <input type="file" name="files"/><br/><br/>

    <input type="submit" value="Submit" id="btnSubmit"/>

</form>


<h1>Ajax Post Result</h1>

<span id="result"></span>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>


</body>

</html>


<script type="text/javascript">

$(document).ready(function () {


    $("#btnSubmit").click(function (event) {


        //stop submit the form, we will post it manually.

        event.preventDefault();


        // Get form

        var form = $('#fileUploadForm')[0];


// Create an FormData object 

        var data = new FormData(form);


// If you want to add an extra field for the FormData

        data.append("CustomField", "This is some extra data, testing");


// disabled the submit button

        $("#btnSubmit").prop("disabled", true);


        $.ajax({

            type: "POST",

            enctype: 'multipart/form-data',

            url: "upload.php",

            data: data,

            processData: false,

            contentType: false,

            cache: false,

            timeout: 600000,

            success: function (data) {


                $("#result").text(data);

                console.log("SUCCESS : ", data);

                $("#btnSubmit").prop("disabled", false);


            },

            error: function (e) {


                $("#result").text(e.responseText);

                console.log("ERROR : ", e);

                $("#btnSubmit").prop("disabled", false);


            }

        });


    });


});

</script>


//Ajax file call

<?php

include 'conn.php';

print_r($_POST);

$name=$_POST['extraField'];

    if ( 0 < $_FILES['files']['error'] ) {

        echo 'Error: ' . $_FILES['files']['error'] . '<br>';

    }

    else {

        move_uploaded_file($_FILES['files']['tmp_name'], 'file/' . $_FILES['files']['name']);

       echo $insert="INSERT INTO ajax_form(Doc,Name)VALUES('".$_FILES['files']['name']."','$name')";

            $sql=mysqli_query($conn,$insert);

    }


?>


Data base file

-- phpMyAdmin SQL Dump

-- version 5.1.3

-- https://www.phpmyadmin.net/

--

-- Host: 127.0.0.1

-- Generation Time: Jun 05, 2022 at 09:35 AM

-- Server version: 10.4.24-MariaDB

-- PHP Version: 7.4.28


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

START TRANSACTION;

SET time_zone = "+00:00";



/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8mb4 */;


--

-- Database: `shubham`

--


-- --------------------------------------------------------


--

-- Table structure for table `ajax_form`

--


CREATE TABLE `ajax_form` (

  `ID` int(11) NOT NULL,

  `Name` varchar(100) NOT NULL,

  `Email` varchar(100) NOT NULL,

  `Mobile` varchar(100) NOT NULL,

  `Dob` date NOT NULL,

  `City` varchar(100) NOT NULL,

  `Gender` varchar(100) NOT NULL,

  `Subject` varchar(100) NOT NULL,

  `Doc` varchar(100) NOT NULL,

  `btid` int(11) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


--

-- Dumping data for table `ajax_form`

--


INSERT INTO `ajax_form` (`ID`, `Name`, `Email`, `Mobile`, `Dob`, `City`, `Gender`, `Subject`, `Doc`, `btid`) VALUES

(1, 'Sam Rana', 'rana20@gmail.com', '789548544556', '2022-06-01', 'New Delhi', 'Male', 'Hindi,English,Math,Others', 'BingWallpaper (1).jpg', 1),

(2, 'Rahul', 'rahul@gmail.com', '8675745654', '2022-05-18', 'Mumbai', 'Male', 'Hindi,English', 'BingWallpaper.jpg', 2),

(3, 'shubham hgjgjghj', 'Jessica@gmail.com', '8675745654', '2022-05-15', 'Mumbai', 'Male', 'Hindi,English', 'BingWallpaper.jpg', 3),

(4, 'Sam Rana', 'rana20@gmail.com', '78956514541', '2022-06-01', 'Mumbai', 'Male', 'Hindi,English,Math', 'BingWallpaper.jpg', 3),

(5, 'Josh Hazel', 'Jessica@gmail.com', '1234585774', '2022-06-02', 'Chennai', 'Female', 'English,Others', 'BingWallpaper (1).jpg', 0),

(6, 'Jessica', 'josh@gmail.com', '12345874', '2022-06-03', 'Bangalore', 'Female', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(7, 'Jeson', 'jeson@gmail.com', '123456987', '2022-06-04', 'Bangalore', 'Male', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(8, 'Josh Hazel', 'Jessica@gmail.com', '56445654546', '2022-06-05', 'Mumbai', 'Female', 'English', 'BingWallpaper (2).jpg', 0),

(9, 'ABC', 'testing@gmail.com', '12345698', '2022-06-01', 'New Delhi', 'Male', 'Hindi,English,Math,Others', 'digital-marketing.jpg', 0),

(10, 'Sam Rana', 'Jessica@gmail.com', '866868686', '2022-06-04', 'Mumbai', 'Female', 'Hindi,English,Math', 'eaccounting.jpg', 0),

(11, 'Sam Rana', 'rana20@gmail.com', '7868686', '2022-06-04', 'New Delhi', 'Male', 'Hindi,English', 'digital-marketing.jpg', 0),

(12, 'Sonica', 'sonica@gmail.com', '1234567890', '2022-05-01', 'New Delhi', 'Female', 'Hindi,English', 'BingWallpaper.jpg', 0),

(13, 'Jessica', 'josh@gmail.com', '12345874', '2022-04-28', 'Bangalore', 'Female', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(14, 'Jessica', 'josh@gmail.com', '12345874', '2022-03-25', 'Bangalore', 'Female', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(15, 'Jessica', 'josh@gmail.com', '12345874', '2022-02-22', 'Bangalore', 'Female', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(16, 'Jessica', 'josh@gmail.com', '12345874', '2022-03-25', 'Bangalore', 'Female', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(17, 'Peterson', 'Peterson@gmail.com', '25857444', '2022-01-22', 'Bangalore', 'Male', 'Hindi,English,Others', 'BingWallpaper (3).jpg', 0),

(18, 'Sam Rana', 'rana20@gmail.com', '458884546654', '2022-06-05', 'Mumbai', 'Male', 'English,Hindi,Others', '', 0),

(19, 'Josh Hazel', 'josh@gmail.com', '123556464', '2022-05-20', 'Hyderabad', 'Female', 'English,Hindi', '', 0),

(20, '', '', '', '0000-00-00', '', '', '', 'eaccounting.jpg', 0),

(21, '', '', '', '0000-00-00', '', '', '', 'eaccounting (1).jpg', 0),

(22, '', '', '', '0000-00-00', '', '', '', 'eaccounting (1).jpg', 0),

(23, '', '', '', '0000-00-00', '', '', '', 'eaccounting.jpg', 0),

(24, '', '', '', '0000-00-00', '', '', '', 'eaccounting.jpg', 0),

(25, '', '', '', '0000-00-00', '', '', '', 'BingWallpaper (3).jpg', 0),

(26, '', '', '', '0000-00-00', '', '', '', 'BingWallpaper (3).jpg', 0),

(27, '', '', '', '0000-00-00', '', '', '', '', 0),

(28, '', '', '', '0000-00-00', '', '', '', '', 0),

(29, '', '', '', '0000-00-00', '', '', '', 'BingWallpaper (2).jpg', 0),

(30, 'Shubham Rana', '', '', '0000-00-00', '', '', '', 'digital-marketing.jpg', 0);


--

-- Indexes for dumped tables

--


--

-- Indexes for table `ajax_form`

--

ALTER TABLE `ajax_form`

  ADD PRIMARY KEY (`ID`);


--

-- AUTO_INCREMENT for dumped tables

--


--

-- AUTO_INCREMENT for table `ajax_form`

--

ALTER TABLE `ajax_form`

  MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;

COMMIT;


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


Comments

Popular posts from this blog

how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php

How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php

How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python