I'm using dropzone.js to upload files and then count the files after submit using php, but why the result is 1 ??
My dropzone js:
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#drop", {
url: 'test.php',
previewsContainer: "#previews",
clickable: "#clickable",
autoQueue: false,
addRemoveLinks: true
});
document.querySelector("#butt").onclick = function() {
myDropzone.enqueueFiles(myDropzone.getFilesWithStatus(Dropzone.ADDED));
};
myDropzone.on("complete", function(file) {
myDropzone.removeFile(file);
});
myDropzone.on('sending', function (file, xhr, formData) {
formData.append("Username", document.getElementById("Username").value);
formData.append("token", document.getElementById("token").value);
});
My test.php :
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if(!empty($_FILES)) {
$count = count($_FILES['file']['name']);
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $count."-".$_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
}else{
return "fail";
}
Or maybe there is another method to count the files ?