2
How do I make dropzoneJS display files that have already been uploaded ? I followed the documentation steps and is uploading normally, but not displaying files already uploaded.
My HTML form code:
<form action="upload.php" class="dropzone" id="my-dropzone"></form>
Script:
<script type="text/javascript">
$(document).ready(function() {
Dropzone.autoDiscover = false;
$("#my-dropzone").dropzone({
//url: "/file/post",
addRemoveLinks : true,
maxFilesize: 0.5,
dictResponseError: 'Erro ao fazer o upload !'
});
})
</script>
<script type="text/javascript">
Dropzone.options.myDropzone = {
init: function() {
thisDropzone = this;
$.get('upload.php', function(data) {
$.each(data, function(key,value){
var mockFile = { name: value.name, size: value.size };
thisDropzone.options.addedfile.call(thisDropzone, mockFile);
thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploads/"+value.name);
});
});
}
};
</script>
Code in upload.php:
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
} else {
$result = array();
$files = scandir($storeFolder);
if ( false!==$files ) {
foreach ( $files as $file ) {
if ( '.'!=$file && '..'!=$file) {
$obj['name'] = $file;
$obj['size'] = filesize($storeFolder.$ds.$file);
$result[] = $obj;
}
}
}
header('Content-type: text/json');
header('Content-type: application/json');
echo json_encode($result);
}
?>
Hi chico, I was looking for a solution similar to yours. I have a question. You were wanting to "get" the records that were already stored at some point for the user to delete and/or upload other files?
– João Manolo
Hello John, both solutions, was through something to upload, download and read the files
– Chico