Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php file upload ajax

$('#ProblemUpload').submit(function(e){
         e.preventDefault();
            var file_data = $('#fileData').prop('files')[0];   //file input id
            var form_data = new FormData();                  
            form_data.append('file', file_data);
            form_data.append('action', 'upload_sheet');
            console.log(form_data);                             
            $.ajax({
                url: '/apis/auth.php', // <-- point to server-side PHP script 
                dataType: 'text',  // <-- what to expect back from the PHP script, if anything
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,                         
                type: 'post',
                success: function(php_script_response){
                    console.log(php_script_response); // <-- display response from the PHP script, if any
                }
            });
     })
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #file #upload #ajax
ADD COMMENT
Topic
Name
9+5 =