admin管理员组

文章数量:1426187

I am using CBM2 plugin within my own custom plugins. I need create my own file uploader so that the file will be stored at a different location than the metapost table within word press. Thus I am creating my own custom field type and using Javascript to call a php file, in order to do the upload.

The problem is the XMLHttpRequest open, says the file does not exist and the log comes back with a "missing page" and yet the files does exist in the plugin folder.

I have tried hard coding the pathway to the file. I also needed to change the 3rd parameter to false (synchronous) in order to get any response at all.

 xhttp.open("POST", "handle_file_upload.php", false); 

Does anyone have any ideas on how to create this "post" so that I can upload the file to the server without it going into the WordPress system?

The code:

 function cmb2_render_callback_photo_upload($field, $escaped_value, 
 $object_id, $object_type, $field_type_object)
 {
    ?>
 <script>
    function UploadFile()
      {
      var xhttp = new XMLHttpRequest();
      xhttp.open("POST", "handle_file_upload.php", true); 
      xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhttp.setRequestHeader("Connection", "close"); 
      xhttp.onload = function () {
      alert(this.responseText);
      };

      var Access     = document.getElementById("myFile");
      var UploadFile = Access.files[0];
      var fd         = new FormData();
      fd.append("myFile", UploadFile);

     alert('before send');
      xhttp.send(fd);
      }
    </script>

    <input type="file" name="myFile" id="myFile" accept="image/*" onchange="UploadFile()"/>
    <?php

 }
 add_action( 'cmb2_render_photo_upload', 'cmb2_render_callback_photo_upload', 10, 5 );

本文标签: plugin developmentXMLHttpRequest to open PHP file responds with Missing Page