cURL+PHP-Trello卡中的附件



你好吗?

任何使用PHP Trello的API发送卡片附件的人都可以更好地向我解释它的工作原理?

我有一个HTML页面,其中有一些输入类型=";文本";,选择和输入类型=";文件";多重

发送数据做trello API,我这样做:

JAVASCRIPT

var files = document.getElementById('Trello attachment'). files;
var formData = new FormData();
for (i = 0; i <myFiles.length; i ++) {
formData.append('file[]', myFiles[i]);
}
var ajax = new XMLHttpRequest();
ajax.open('POST', 'assets/php/ajaxResponse.php');
ajax.send(formData);

PHP ajaxResponse

if (! empty ($_ FILES)) {
for ($i = 0; $i <count ($_FILES['file']['name']); $i++) {
$chAttachment = curl_init();
curl_setopt($chAttachment, CURLOPT_URL, 'https://api.trello.com/1/cards/tQxhxRJO/attachments?key=key&token=token');
curl_setopt($chAttachment, CURLOPT_POSTFIELDS, http_build_query(
variety(
'name' => $_FILES ['file'] ['name'] [$i],
'file' => $_FILES ['file'] ['tmp_name'] [$i]
)
));
curl_setopt($chAttachment, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($chAttachment);
curl_close($chAttachment);
print_r($result);
}
}

我面临的问题是,使用API,我可以在tQxxRJO ID卡上创建附件,然而,在trello中,它们显示文件名,因为通过curl_setopt,我通过name param设置了我想要的名称,但所有上传的文件都有14个字节,这意味着它上传不正确,当我点击下载或打开trello卡上的附件时,我可以下载文件,但是,我所有名为Upload的文件,如果你用VSCode打开文件,即内容包含我发送的文件名。

有人知道如何通过cURL正确上传吗?

非常感谢!

已解决!

如果这里有人需要任何关于如何在trello中使用cURL上传文件的帮助,这里有诀窍!

for($i = 0; $i < count($_FILES['file']['name']); $i++){
$args = array(
'file' => new CurlFile($_FILES['file']['tmp_name'][$i], $_FILES['file']['type'][$i],$_FILES['file']['name'][$i]),
'key'   => 'mykey',
'token' => 'mytoken',
'mimeType' => $_FILES['file']['type'][$i],
'name' => $_FILES['file']['name'][$i]
);

$chAttachments = curl_init();
curl_setopt($chAttachments, CURLOPT_URL,'https://api.trello.com/1/cards/' . $jsonDecoded['shortLink'] . '/attachments/');
curl_setopt($chAttachments, CURLOPT_POST,1);
curl_setopt($chAttachments, CURLOPT_POSTFIELDS, $args);
$resultAttachments = curl_exec($chAttachments);
curl_close($chAttachments);
}

最新更新