admin管理员组文章数量:1430142
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
版权声明:本文标题:plugin development - XMLHttpRequest to open PHP file responds with Missing Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745472629a2659818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论