Jump to content

Can't make upload work


homer.j.simpson

Recommended Posts

I'm having trouble with file element. My code is to create a file upload form when user click specific button and there isn't any problem creating it. But when user click submit button, server side doesn't receive the file . I test this by using PHP code var_dump($_FILES). The function only returned empty array. The file element work well if it is created statically and var_dump($_FILES) return file related info. Any idea to overcome this?

var myform = document.createElement("form");myform.setAttribute("action","index.php");myform.setAttribute("method","post"); myform.setAttribute("id","myform"); myform.setAttribute("enctype","multipart/form-data");var myfile = document.createElement("input");myfile.setAttribute("type","file");myfile.setAttribute("name","myfile");myform.appendChild(myfile);var sbmt = document.createElement("input");sbmt.setAttribute("type","submit");myform.appendChild(sbmt);body[0].appendChild(myform);
Link to comment
Share on other sites

I am not experimented at all with DOM, but, input objects are linked to the form object, for example when I want to access an input field I use document.formname.inputname. In your case, the 'myfile' input object is not linked to the 'myform' form object. Probably it should bevar myfile = myform.createElement("input");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...