php - Dropzone 只为最后一个文件构建缩略图
问题描述
我需要将现有文件预加载到 Dropzone-Div 的实例中。我在网上查了一些类似的问题,但没有找到。我想在旅途中创建缩略图,只要只有一个文件,它就可以很好地工作。如果有超过 1 个文件,它只会生成最后一个文件的缩略图。
这是我的 .dropzone 中的初始化函数:
init: function() {
// Create the mock files:
var dropZoneInstance = this;
// Load Files
$.ajax({
url: 'ajaxcall.php',
data: {id: profil,zuordnung: zuordnung, ajaxcall: 'readAnhänge'},
success: function (response) {
var files = JSON.parse(response);
for (i = 0; i < files.length; i++)
{
var obj = files[i];
console.log(obj);
dropZoneInstance.files.push(obj);
dropZoneInstance.emit("addedfile", obj);
dropZoneInstance.createThumbnailFromUrl(obj,
dropZoneInstance.options.thumbnailWidth,
dropZoneInstance.options.thumbnailHeight,
dropZoneInstance.options.thumbnailMethod, true, function (thumbnail)
{
dropZoneInstance.emit('thumbnail', obj, thumbnail);
}
);
dropZoneInstance.emit("complete", obj);
}
}
});
}
这是 JSON 的 PHP 代码:
function ReadFromZuordnung($zuordnung = 0)
{
$var = Array();
global $dbh;
global $user;
$query = $dbh->prepare("
SELECT
anhang_id AS id
FROM
tbl_anhang
WHERE
anhang_profil = :profil
AND
anhang_zuordnung = :zuordnung
");
$query->bindValue(':profil', $this->getId(), PDO::PARAM_INT);
$query->bindValue(':zuordnung', $zuordnung, PDO::PARAM_INT);
$query->setFetchMode(PDO::FETCH_CLASS, 'Test');
$query->execute();
while($row = $query->fetch())
{
$var[] = Array("id"=>$row->getId(),"name"=>$row->getName(),"size"=>0,"dataURL"=>$this->getUploadPfad().$row->getName());
}
echo json_encode($var);
}
这就是我的test.php:
<div id="dropzone" class="dropzone" profil="1">
<div class="dz-default dz-message"></div>
</div>
这就是结果:https ://imgur.com/9ezsnrk
我想为每个文件都有缩略图,而不仅仅是最后一个。
有什么建议么?
解决方案
好的,经过两天的搜索,我自己得到了答案:
只是改变
var obj = files[i];
至
let obj = files[i];
解决了问题。
当他遇到同样的问题时,也许其他人会节省一些时间。
推荐阅读
- php - 高级自定义字段图像
- python - 无法解释 Seaborn 线图色调输入
- python - 我得到 TypeError: 'NoneType' object is not iterable, 尝试过滤列表时
- javascript - 如何在 JavaScript 中添加动态创建的脚本标签属性?
- c++ - unsigned long long int 在循环中的奇怪行为
- r - 如果使用 updateselectInput() 会快速刷新 DT
- java - 在 IntelliJ 上生成 JAR
- asp.net-mvc - Control + F5 对某些图像随机给出 403 禁止错误
- azure-active-directory - 是否有 Graph API 可以通过 AD B2C 获取所有登录活动?
- xml - 在一行中使用 DFDL 解析输入