php - Using HTML file type in JavaScript -
this question has answer here:
- html5 ajax multiple files upload 1 answer
- how can upload files asynchronously? 25 answers
does know how manage <input type="file" id="myfile" />
in javascript can send file php code?
i have this:
<input type="file" id="myfile" /> <input type="button" value="file" onclick="usefile()" />
then, in javascript want use file user uploaded because want use in php code.
how file , send php parameter?
function usefile() { var myfile = document.getelementbyid("myfile"); //does work? // how send php? }
i hope me.
thanks lot.
can submit form? if so, it's simple. here's html:
<form method="post" action="myscript.php"> <!-- make form tag sends input (using post) php script --> <input type="file" id="myfile" /> <!-- had above --> <input type="submit"/> <!-- create submit button that, when clicked, send file server , redirect page myscript.php --> </form>
if you're not sure post is, check out site: http://www.restapitutorial.com/ , read document: http://www.mediafire.com/view/6hmhaygp099gfdh/restful_best_practices-v1_1.pdf .
however, if can't submit form, can file registering onchange handler in javascript. check out answer more info: how files <input type='file' .../> (indirect) javascript .
do have jquery on project? makes easy send files via post server. read more here: http://api.jquery.com/jquery.post/ .
if don't have jquery can use xmlhttprequest send post. page has information on how it: http://www.openjs.com/articles/ajax_xmlhttp_using_post.php , here docs xmlhttprequest: https://developer.mozilla.org/en-us/docs/web/api/xmlhttprequest
i hope helps!
Comments
Post a Comment