Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read FormData object in php

Tags:

People also ask

How can I get form data in PHP?

$_POST['firstname']: The form data is stored in the $_POST['name as key'] variable array by PHP since it is submitted through the POST method, and the element name attribute value – firstname (name=”firstname”) is used to access its form field data.

How do I read a FormData file?

There is no way to retrieve the files after you've appended them in to a formData-object I believe. You'll have to send the formData-object somewhere and then get the files from a req-object or something like that. The code is taken from : AngularJS: how to implement a simple file upload with multipart form?

How do I find my FormData value?

get() The get() method of the FormData interface returns the first value associated with a given key from within a FormData object. If you expect multiple values and want all of them, use the getAll() method instead.

What is FormData ()?

The FormData interface provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the fetch() or XMLHttpRequest. send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data" .


Hello everyone I am posting a sample code in which I am uploading a file using Ajax JQuery. All thing works fine but I want to read the file content in my php code. So what is the syntax to read it?

    <?php

?>

<!--================================html==================================================-->

<html>
<head>
    <title>AJAX UPLOAD</title>
    <script type="text/javascript" src="jquery-2.0.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('#Button_').click(function(){
                alert("hi");
                var name= document.getElementById('File_');
                 var alpha=name.files[0];
                console.log(alpha.name);
                 var data= new FormData();
                 data.append('file',alpha);
                 $.ajax({
                 url:'process.php',
                 data:data,
                 processData:false,
                 contentType:false,
                 type:'POST',
                 success:function(msg){
                 alert(msg);
                 }
                 });
            });
        });
    </script>
</head>
<body>
    <input type="file" name="File" id="File_"/>
    <input type="button" name="Button" id="Button_" value="UPLOAD">
</body>
</html>

Now I do not know how to read the file data sent via Ajax. So please let me know the code