使用 dropzone 向后端发送附加数据

2024-08-09php开发问题
0

本文介绍了使用 dropzone 向后端发送附加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试通过 dropzone 将图像文件的特定 - 已经知道 - 位置 ID 发送到后端,该 ID 将上传到服务器上.虽然正在使用 formData.append(),但我看到没有附加任何内容.而只是显示了这个FormData {}".

I am trying to send through dropzone a specific -already known- position ID of an image file to the backend, which is going to be uploaded on the server. Although the formData.append() is being used, I see that nothing is appended.Instead just this "FormData {}" shows up.

dropzoneObject.on("sending", function(file, xhr, formData){
    var nameOfFile = $(file.previewElement).find(".dz-filename").text();
    var positionOfFile = fpos;
    //console.log("The file who's being sent is named: "+nameOfFile+" and its position id is: "+positionOfFile);
    formData.append("fpos", fpos);
});

我希望在示例中看到 fpos=16;

I expect to see in example fpos=16;

推荐答案

不知道你的具体错误,但这里有一个简单的例子,说明如何使用 jQuery 使用 dropzone 发送附加数据并在后端使用 php 接收它.

Don't know about your particular error, but here is a simple example of how to send additional data with dropzone using jQuery and receiving it with php on the backend.

html:

<form id="myForm" class="dropzone"></form>

js:

Dropzone.autoDiscover = false;
$('.dropzone').dropzone ({
        url: "upload.php",
        init: function() {
            this.on("sending", function(file, xhr, formData){
                formData.append("fpos", 777)
            }),
            this.on("success", function(file, xhr){
                alert(file.xhr.response);
            })
        },
});

成功事件只是为了演示如何访问服务器发送的响应:

The success event is only to demonstrate how to access the response send from the server:

php:

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
    {
        echo "RECEIVED ON SERVER: 
";
        echo "FILES: 
";
        print_r($_FILES);
        echo "$_POST: 
";
        print_r($_POST);
    }

php 只是将接收到的相同数据发送回客户端,只是为了显示可访问的位置.

The php simply sends back to client the same data received, just to show where is accessible.

这篇关于使用 dropzone 向后端发送附加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17