I would like to know if it is possible to upload files that have been downloaded using Dropzone. For example, add a link or download button to the file that appears in dropzone.
Code for downloading and displaying already downloaded files:
index.php
<html> <head> <link href="css/dropzone.css" type="text/css" rel="stylesheet" /> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="dropzone.min.js"></script> <script> 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.emit("addedfile", mockFile); thisDropzone.emit("thumbnail", mockFile, "uploads/"+value.name); }); }); thisDropzone.on("addedfile", function(file) { var removeButton = Dropzone.createElement("<button>Remove</button>"); var _this = this; removeButton.addEventListener("click", function(e) { e.preventDefault(); e.stopPropagation(); _this.removeFile(file); }); file.previewElement.appendChild(removeButton); }); thisDropzone.on("removedfile", function(file) { if (!file.serverId) { return; } $.post("delete-file.php?id=" + file.serverId); }); } }; </script> </head> <body> <form action="upload.php" class="dropzone" id="my-dropzone"></form> </body> </html>
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); } ?>
any help would be much appreciated
Vitor source share