0
votes

In my php page, I have a form as:

   <form enctype = 'multipart/form-data' method="post">

        Select File:
        <br/>
        <input type="file" name="file" /> 
        <input type="submit" name="upload" value="Upload" />

    </form>

When I submit the form on clicking the submit 'upload', the following php is called which is on the same php page:

<?php
       if (isset($_POST['upload'])) {  ...Do stuff... } 
?> 

Now, I dont want to use the submit in my html form and want to trigger this php whenever a file in the input type file is selected. i.e. the form should be submitted automatically on file selection without the submit button. Also, i want a if condition such as isset($_POST['']) and dont want to use just a post check as $_SERVER['REQUEST_METHOD'] == 'POST'

Any help will be appreciated.

1
You could accomplish this by placing a js event listener on the file input. When this 'changed' listener fires, submit your form using js. Give this a try, and if you stumble along the way, post your attempt here.mambrow

1 Answers

0
votes

All you have to set an event handle for change in input file

<script type="text/javascript">
$(function() {
 $("input:file").change(function (){
   $('form').submit();
 });
});
</script>