0

I don't have any idea to copy a file from client system to server. Short Description

  • I am using upload folder dialog box to upload a multiple file from particular path.
  • XML file is mandatory, because i need to extract some information to process
  • While upload event i read all the information i need to process

    $("#myInput").change(function() {
    var names = [];
    var formData = new FormData();
    for (var i = 0; i < $(this).get(0).files.length; ++i)
    {
    var F_name= $(this).get(0).files[i].name;
    var extension = F_name.replace(/^.*\./, '');
    if(extension != "xml" && extension != "db"){
    formData.append('userfiles[]', $(this).get(0).files[i], F_name);
    }
    else if(extension == "xml"){    
    //Gathering info
    }}    });
    

    User interface fields are filled automatically after this process and user have to fill some more fields. While user click process button in server side i create folder and some new XML files too. Everything is fine except , copy a file from client to server.

//Jquery

$("#process_but" ).click(function() {
$.ajax({
type: "POST",
url: "Asset/PHP/function.php",
data: {action: "action1", DOI:doi, TLA:tla, STITLE:S_Title, SHEAD:S_Head, SLINK:S_Link, LTYPE:link_type, DESC:description, ATITLE:Art_title, JTitle:JOU_title, ANAME:Author_name, FSHARE:Fig_share, FNAMES:filenames, FCOUNT:filecount},
success: function(response) {                       
if(response == 1)
{alert("success");}
else
{alert("Something goes wrong.....");}
},
error: function() {
alert("Error");
}
});
});

//php

<?php
session_start();
$action = $_POST['action'];
if($action == "action1")
{
//what i have to do
}
?>
Ancy
  • 35
  • 2
  • 9
  • Possible duplicate of [Why would $\_FILES be empty when uploading files to PHP?](https://stackoverflow.com/questions/3586919/why-would-files-be-empty-when-uploading-files-to-php) – Michel Jun 23 '18 at 05:54
  • i post my code and explain the way i used. but i don't know how to append to my current code – Ancy Jun 23 '18 at 06:45
  • formData.append('userfiles[]', $(this).get(0).files[i], F_name); is this any use to store my file. how can i transfer files via ajax????? – Ancy Jun 23 '18 at 06:46

0 Answers0