Php HTML文件上载未将文件发送到$\u文件

Php HTML文件上载未将文件发送到$\u文件,php,forms,file-upload,Php,Forms,File Upload,我有一个html表单,当用户选择一个文件并提交它时,php文档中的$u文件不会收到它。主要的焦点是表单,当我点击submit时,没有文件被提交,但onclick事件被触发。并且没有错误消息 <form id="artist_post" enctype="multipart/form-data" method="post" onsubmit="return " action="php_parsers/newsfeed_system.php"> <textarea id="

我有一个html表单,当用户选择一个文件并提交它时,php文档中的$u文件不会收到它。主要的焦点是表单,当我点击submit时,没有文件被提交,但onclick事件被触发。并且没有错误消息

    <form id="artist_post" enctype="multipart/form-data" method="post" onsubmit="return " action="php_parsers/newsfeed_system.php">
<textarea id="statustext" onkeyup="statusMax(this,250)"></textarea>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input id="audioUpload" type="file" name="audioUpload" accept="audio/*" />
<input type="submit" value="Post" id="statusBtn" onclick="postToStatus('status_post','a','statustext')"/>
</form>
javascript从表单中获取信息,并通过ajax将其发送到php

function postToStatus(action,type,ta){
var data = _(ta).value;
if(data == ""){
    alert("Type something first");
    return false;
}

// Checks to see if user uploaded a file to send with post 
if(_("audioUpload").value != "") { 
    type = "c";
}   

_("statusBtn").disabled = true;
var ajax = ajaxObj("POST", "php_parsers/newsfeed_system.php");
ajax.onreadystatechange = function() {
    if(ajaxReturn(ajax) == true) {
        //Pull some info from whatever the php doc returns
    }
}

ajax.send("action="+action+"&type="+type+"&data="+data);
}
function ajaxObj(meth, url) {
var x = new XMLHttpRequest();  // create new http request 
x.open( meth, url, true );  // open request and pass it a method and a url to post it to 
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
return x;
}
// Modular function that externalizes readyState and status check
function ajaxReturn(x) {
if(x.readyState == 4 && x.status == 200) {
    return true;
    }
}
您的
需要删除。您使用的是AJAX,因此绕过了表单操作序列。我已经在我的服务器上创建了一个副本,它可以在没有副本的情况下工作

我建议您时不时地将其扔进JSFIDLE中,然后点击顶部的“整洁”按钮。否则,到目前为止代码做得很好


如果您想看到我的复制副本在运行:

您的javascript
postToStatus()
函数包含什么?首先取出
onsubmit=“return”
onclick=“postToStatus()”
,除非您正确调用了这些函数。您是否试图通过javascript发布文件?因为如果没有jquery,它将无法工作lib@JerkoW.Tisler“没有jquery库”;您确实知道jquery是用javascript编写的,因此,使用jquery所能做的一切都可以不用它(在原始javascript中)?是的,您可以用JS来做。我的意思是,是的,你是对的,JQuery是用javascript编写的,但老实说,我真的怀疑你是否编写了1000多行代码来用本机JSF上传文件。当我取出“”时,它仍然没有将文件发送到php文档。我同意并感谢您的意见,我认为它不起作用,因为我绕过了使用ajax的方法。然而,我似乎不明白为什么文件不会发送。Javascript无法读取该文件,这是我最初编写该文件的方式。还有其他建议吗?
function postToStatus(action,type,ta){
var data = _(ta).value;
if(data == ""){
    alert("Type something first");
    return false;
}

// Checks to see if user uploaded a file to send with post 
if(_("audioUpload").value != "") { 
    type = "c";
}   

_("statusBtn").disabled = true;
var ajax = ajaxObj("POST", "php_parsers/newsfeed_system.php");
ajax.onreadystatechange = function() {
    if(ajaxReturn(ajax) == true) {
        //Pull some info from whatever the php doc returns
    }
}

ajax.send("action="+action+"&type="+type+"&data="+data);
}
function ajaxObj(meth, url) {
var x = new XMLHttpRequest();  // create new http request 
x.open( meth, url, true );  // open request and pass it a method and a url to post it to 
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
return x;
}
// Modular function that externalizes readyState and status check
function ajaxReturn(x) {
if(x.readyState == 4 && x.status == 200) {
    return true;
    }
}