I am using fileinput widget form krajee: http://plugins.krajee.com/file-input
What I am doing wrong using \'upload\' method ? When I upload files by pressing upload but
I was having the same issue, but I couldn't find a good solution, so I came up with a workaround.
I'm using the 'filebatchuploadcomplete' event, so I know when all the files in the batch are uploaded succesfully (even if there's only one file in the batch to be uploaded). When this event is triggered, I call 3 methods of the fileinput inside the closure function to clear, reset and re-enable the fileinput area (dropzone too, if you're using one).
THIS METHOD WORKS REGARDLESS IF THE ABOVE MENTIONED ERROR IS THROWN OR NOT BY THE PLUGIN.
Here's my sample:
$('#myFileuploadArea').fileinput({
//set the upload options here
...
...
...
}).on("filebatchselected", function(event) {
// trigger upload method immediately after files are selected
$('#myFileuploadArea').fileinput("upload");
}).on('filebatchuploadcomplete', function(event) {
// this part is triggered when all files are succefully
// uploaded from the batch, even if there was only one file selected
console.log('ALL FILES IN BATCH UPLOADED SUCCESSFULLY');
$('#myFileuploadArea').fileinput('refresh');
$('#myFileuploadArea').fileinput('reset');
$('#myFileuploadArea').fileinput('enable');
});
If you are just looking for a file upload plugin, I recommend Ravishanker Kusuma's Hayageek jQuery File Upload plugin
:
http://hayageek.com/docs/jquery-upload-file.php
He breaks down the process into three simple steps, that basically look like this:
<head>
<link href="http://hayageek.github.io/jQuery-Upload-File/uploadfile.min.css" rel="stylesheet"> // (1)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://hayageek.github.io/jQuery-Upload-File/jquery.uploadfile.min.js"></script> // (1)
</head>
<body>
<div id="fileuploader">Upload</div> // (2)
<script>
$(document).ready(function(){
$("#fileuploader").uploadFile({ // (3)
url:"my_php_processor.php",
fileName:"myfile"
});
});
</script>
</body>
The final step is to have the PHP file specified in the jQuery code (in this case my_php_processor.php
) to receive and process the file:
my_php_processor.php:
<?php
$output_dir = "uploads/";
$theFile = $_FILES["myfile"]["name"];
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);
Note the relationship between myfile
in the PHP ($_FILES["myfile"]
), and the filename specified in the jQuery code block.
The answer is that I have older version of control (4.1.6) and documentation I have red is newer (4.1.7). In 4.1.6 upload method must have parameters, in 4.1.7 not In 4.1.6 the solution might be use uploadBatch which has no parameters (what I finally did)