Dropzone是如此强大和令人敬畏,你可以做任何事情。
要遵循的步骤 - >
1)你必须创建一个服务器端脚本,这将 得到所有的文件名和它的大小并将其作为JSON响应的第一。
PHP代码:
foreach($myitemfiles as $file){ //get an array which has the names of all the files and loop through it
$obj['name'] = $file; //get the filename in array
$obj['size'] = filesize("uploadsfolder/".$file); //get the flesize in array
$result[] = $obj; // copy it to another array
}
header('Content-Type: application/json');
echo json_encode($result); // now you have a json response which you can use in client side
2)现在你可以使用响应显示上传files.Write悬浮窗初始化函数里面下面的代码
JavaScript代码:
init: function() {
var thisDropzone = this;
$.getJSON('get_item_images.php', function(data) { // get the json response
$.each(data, function(key,value){ //loop through it
var mockFile = { name: value.name, size: value.size }; // here we get the file name and size as response
thisDropzone.options.addedfile.call(thisDropzone, mockFile);
thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploadsfolder/"+value.name);//uploadsfolder is the folder where you have all those uploaded files
});
});
}
注意:不采取文件名中的整个文件的url路径只需要文件名本身就是它。
This works
如果您限制了可以上传的文件数量,则必须添加myDropzone.files。推(mockFile);继续执行此上传限制。 –
真的,您应该始终包含来自Kent的行(myDropzone.files.push(mockFile)),否则调用myDropzone.removeAllFiles()将不会删除预先填充的文件。 – Justin