- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下是我使用 dropzone.js 插件在服务器上上传文件的代码:
var file_up_names = new Array;
var duplicate_files = new Array;
var token = $('input[name=_token]').val();
Dropzone.autoDiscover = false;
var dropzone = $("#addPhotosForm").dropzone({
addRemoveLinks: true,
dictRemoveFileConfirmation: "Do you want to remove this image?",
dictDefaultMessage: "Drop images here to upload",
dictRemoveFile: "Remove photo",
init: function() {
this.on("success", function(file, response) {
if (response.status === 1) {
file_up_names.push(response.filename);
$(file.previewTemplate).append('<span class="server_file_path hide">' + response.newfilename + '</span>');
} else if (response.status === 2) {
duplicate_files.push(response.filename);
this.removeFile(file);
}
}),
this.on("queuecomplete", function() {
var html = "Photos added successfully!";
$('#photoUploadSuccess').html('');
$('#photoUploadError').html('');
$('#photoUploadSuccess').removeClass('hide');
$('#photoUploadError').addClass('hide');
if (file_up_names.length > 0) {
if (duplicate_files.length > 0) {
html += " Following photos are skipped as those are already uploaded.";
html += "<ul>";
for (var i = 0; i < duplicate_files.length; ++i) {
html += "<li>";
html += duplicate_files[i];
html += "</li>";
}
html += "</ul>";
}
$('#photoUploadSuccess').html(html);
} else if (duplicate_files.length > 0 && file_up_names.length === 0) {
html = "Following photos already exists. Please check to see if it already exists and try again.";
html += "<ul>";
for (var i = 0; i < duplicate_files.length; ++i) {
html += "<li>";
html += duplicate_files[i];
html += "</li>";
}
html += "</ul>";
$('#photoUploadSuccess').addClass('hide');
$('#photoUploadError').removeClass('hide');
$('#photoUploadError').html(html);
} else {
html = "Photos not uploaded!";
$('#photoUploadSuccess').addClass('hide');
$('#photoUploadError').removeClass('hide');
$('#photoUploadError').html(html);
}
duplicate_files = [];
file_up_names = [];
setTimeout(function() {
$('#photoUploadSuccess').html('');
$('#photoUploadError').html('');
$('#photoUploadSuccess').addClass('hide');
$('#photoUploadError').addClass('hide');
}, 5000);
}),
this.on("removedfile", function(file) {
var server_file = $(file.previewTemplate).children('.server_file_path').text();
// Do a post request and pass this path and use server-side language to delete the file
var token = $('input[name=_token]').val();
$.ajax({
type: 'POST',
headers: {'X-CSRF-TOKEN': token},
url: "{{ URL::route('removePhotos') }}",
data: "file_name=" + server_file,
dataType: 'html'
});
})
}
});
下面是我的服务器代码,它获取文件的 md5 并将其存储在服务器上,下次当用户再次上传相同的图像时,它会检查数据库,如果发现相同的 md5_file 结果,则不允许上传图像。当我使用简单表单时它可以工作,但在 dropzone 上它不起作用:
$tempFile = $_FILES['file']['tmp_name'];
$md5_check = md5_file($tempFile);
//check if same image uploaded before
$duplicateCheck = Photos::where('userId', '=', $this->userId)->where('md5_check', '=', "$md5_check")->where('isDeleted', '=', 0)->count();
我发现,如果我一起上传相同的图像,它将无法正常工作,并且会从数据库返回计数 0。但是,如果我单独上传相同的图像,例如上传图像后,再次上传相同的图像,它会从数据库中获取计数并给出该图像已存在的消息。也许是由于 dropzone 异步调用造成的,但不知道如何处理这个问题。
最佳答案
这是因为当您上传多个图像时 $_FILES
包含一组文件,因此您应该使用 foreach
循环它并在该循环内执行操作。
您可以通过插入以下代码来检查上传超过 1 个文件时发生的情况:
var_dump($_FILES);
或者,如果您希望结果更具可读性:
echo "<pre>".print_r($_FILES, true)."</pre>";
检查$_FILES
的结构,当您上传超过1个文件时,它应该是一个文件数组。
关于javascript - Dropzone js 使用 md5_file 检查重复文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48748954/
我想在 md-toolbar 中使用 mf-tabs,我使用 Sithdown 在 https://github.com/angular/material/issues/1076 中提供的解决方案 它
我是新手,我设法用服务提供的数据实现了我的 md-table。现在我正在尝试实现过滤器、排序和分页功能,但我认为我做错了什么。 这是我的组件: import { Component, OnInit,
我必须打开一个 md-dialog,其中包含一个带有两个选项卡的 md-tab-group。 md-dialog 可以从两个按钮打开,这两个按钮应该打开相应的选项卡。打开 md-dialog 的模板:
我正在尝试做这样的事情: {{item}}
我正在尝试使用 md-datepicker 遍历一个月的时间间隔,因此我创建了这个 codepen 示例以便更好地演示: http://codepen.io/anon/pen/ygBGOg 当单击“P
这是关于 Codepen 的例子. 我正在设置 md-row-height="30px" 然后计算 md-rowspan 使其等于元素数 + 1。(头部加一) {{ t
当我频繁切换 md-tabs 时,Md-tabs 切换正确但多个 md-tab-item 元素同时具有“md-active”类,所以我看不到选项卡的内容是事件的,因为它与其右侧选项卡的内容重叠。 据我
我想将操作放在同一数据行上,我有两个操作,为此我使用按钮和图标作为下面的代码。 {{item.codigo}} {{it
在我的对象列表中,我可以激活/非事件对象。因此,一个图标执行事件操作,另一个图标执行非事件操作,并且两者都在同一个 md-list 中。 This is what i'm tring to do 代码
如前所述 Angular-Material md-autocomplete's documentation : The md-autocomplete uses the the md-virtual-
我也在使用 Angular 1 和 Angular Material 。我想在 ng-repeat 中使用 md-subheader 和多个 md-virtual-repeat-container。您
我正在使用 Angular Material 。 当我创建自己的指令并将其添加到 md-tab-label 时,例如 Label 然后自定义指令也应用于一些“md-dummy-tab”。 但是
我在我的项目中使用 Angular Material 有一段时间了。在使用 md-select 时,我遇到了一个问题,即出现重复的 md-option 值错误。 我知道 md-options 采用唯一
我正在根据单选按钮选择设置自动完成验证 md-require-match = true/false。 默认验证是 md-require-match = true 这样用户应该从自动完成列表中选择一个项
这个问题在这里已经有了答案: Changing capitalization of filenames in Git (11 个答案) 关闭 3 年前。 我使用“readme.md”创建了我的存储库
Github有办法吗?在例如 README.md 中包含 md 文件? # Headline Text [include](File:load_another_md_file_here.md) 它不应
我正在使用 AngularJs 开发这个动态过滤系统,并试图找出如何将 color 和 size 选项转换为在两个下拉列表中(每个类别一个)。 我尝试了以下代码,该代码成功添加了下拉列表以及选择框中的
var app = angular.module('tabsDemo', ['ngMaterial']); app.controller('TabsController',tabsController
在 md-tab 指令内嵌套 md-select 和搜索输入时遇到问题。 有两个问题: 选择框展开后,必须向上滚动才能查看搜索输入 搜索输入实际上不接受任何文本 我做了一个codepen为了更好地说明
我正在尝试处理这个片段,其中自动完成功能嵌入在芯片中。但从自动完成中选择的项目不会转换为筹码。 自动完成的数据采用以下方式:{name:"John Doe", id:"1"} 哪里错了,请指教。 问候
我是一名优秀的程序员,十分优秀!