javascript - Submitting a PHP upload once files have been selected -


i have image upload script using php simple multiple file select , upload function below:

mysql_connect("localhost", "root", "") or die("error"); mysql_select_db("repo") or die("error");  $imgerror = ''; if(isset($_post['log'])){     foreach($_files['files']['tmp_name'] $key => $name_tmp){         $name = $_files['files']['name'][$key];         $tmpnm = $_files['files']['tmp_name'][$key];         $type = $_files['files']['type'][$key];         $size = $_files['files']['size'][$key];         $dir = "content/images/".$name;         $move = move_uploaded_file($tmpnm,$dir);         if($move){             $hsl = mysql_query("insert files values('','$client','$name','$type','$size',now())");              if ($hsl){                 $imgerror = "image(s) uploaded successfully";             } else {                 $imgerror = "cannot connect database";             }         } else {             $imgerror = "no images selected";         }     } } 

html:

<div class="uploadcontainer">     <div><i><?php echo $imgerror ?></i></div>     <form action="" method="post" enctype="multipart/form-data">         <input type="file" name="files[]" multiple>         <input type="submit" name="log" value="upload">     </form> </div> 

i did find information using jquery question here have no idea how implement code, or maybe suggest alternative. trying select files, , make automatically submit without pressing submit button.

any appreciated, thanks

the onchange event works inputs type file. next code auto-submits "once files have been selected" (tested in mozilla firefox) :

<html>   <head>     <script type="text/javascript">  function on_change () { alert( "file(s) chosen!" +          "\n\n" +          "click submit files upload." );   document.getelementbyid( "frm" ).submit(); }     </script>   </head>   <body>     <form id="frm" action="upload.php" method="post" enctype="multipart/form-data">         <input type="file" name="files[]" multiple onchange="on_change()">         <input type="submit" name="log" value="upload">     </form>   </body> </html> 

of course, have remove javascript "alert" window, it's there show "onchange" event works.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -