HTML upload file using AJAX and PHP script - help? -


i trying perform task may not possible. haven't found same scenario yet around internet.

i have 4 fields that, on click, call javascript function ajax call data php file.

the fields filling row in database , php query new set of data, , user see it. part of data image user can click on , expand.

the ajax call works, expanding image works, adding image via upload not, breaking whole thing.

here snippet of html form:

entry: <input type='text' id='entry' /> stop: <input type='text' id='stop' /> final: <input type='text' id='final' /> chart: <input type='file' id='chart' value='get chart'/> <input type='button' onclick='addresult()' value='add' /> 

the addresult() processes things this:

var entry = document.getelementbyid('entry').value; var stop = document.getelementbyid('stop').value; var final = document.getelementbyid('final').value; var chart = document.getelementbyid('chart').value; var querystring = "?entry=" + entry + "&stop=" + stop + "&final=" + final + "&chart=" + chart + "&loggedin=true"; ajaxrequest.open("get", "addresult.php" + querystring, true); 

nothing special, taking data , sending addresult.php response. here process handling 'chart' upload data in addresult.php:

$chart = $_get['chart']; $chart_loc = "../img/".basename($_files[$chart]['name']); move_uploaded_file($_files[$chart]['tmp_name'], $chart_loc); if(($entry != "") && ($stop != "") && ($final != "") && ($chart_loc != "")){            mysql_query("insert resultsmod values (now(),'".$entry."','".$stop."','".$final."','".$chart_loc."')") or die(mysql_error());         } 

when click 'add' button, nothing, , before added upload file field, working fine. must doing wrong handling file.

i've never worked upload data before, don't know if sending data allowed (without form submission , passing file data through javascript php file). may doing incorrect move_uploaded_file function.

the goal of course have real time update of new data form, including uploaded image. (i know code simple , add once functional) appreciated, thanks!

you trying upload file using ajax, not posible. best approach manage file upload separately, maybe through swf-upload


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -