Doubt JS with input type file

2

Good evening, I need some help on the input part, I have a <input type="file" id="filesend" name="file" multiple/>

How do I make a script that automatically detects when the user places a file in the input and sends $_POST['file']; to upload.php ?

    
asked by anonymous 02.12.2015 / 00:56

2 answers

4

Side, client:

<form enctype="multipart/form-data" action="upload.php" method="POST">
    <input type="file" name="file" onchange="this.form.submit();" id="file"/>  
</form>

On the server side use $ _FILES as @Wallace Maxters proposes.     

02.12.2015 / 01:36
1

First, do not use $_POST to get files. You use $_FILES .

Second, to upload as soon as you select the file, it can be done with jQuery.

I have developed a plugin to be able to do this in an easier way.

See:

link

Very simply, it can be done like this:

$('#filesend').change(function () {

    if (!$(this).val()) return alert('Selecione um arquivo');

     $(this).ajaxUpload({url: 'testando'});
});
    
02.12.2015 / 01:28