【问题标题】:Teamwork api, how send file?Teamwork api,如何发送文件?
【发布时间】:2015-12-25 11:45:19
【问题描述】:

我正在使用 ZF1 表单获取数据并使用 cURL 将它们发送到 Teamwork API。 我尝试在任务列表上创建新任务,没关系。问题是,当我尝试附加文件时,服务器响应是:

"MESSAGE":"找不到临时文件引用","STATUS":"错误"

我该怎么办?

请帮忙。

我的表格:

$this->setName('editForm')
     ->setAttrib('class', 'no-store')
     ->setAttrib('enctype', 'multipart/form-data"');

$this->createElement('file', 'pendingFileAttachments')

我只是从 $_POST 'pendingFileAttachments' 中获取并尝试在 json 中编码并发送。可能需要获取文件而不仅仅是文件名,这是真的吗?

提前感谢您的帮助。

编辑:

所以,我发现我应该先将文件上传到 Teamwork API,然后在创建任务 POST cURL 函数中使用上传的文件引用。

现在我已经将文件上传到服务器的硬盘上,并且在我的 php 脚本中我使用“realpath”来查找它确实存在并且感觉良好。

比我用这个代码:

$data["file"] = $filePath;

$channel = curl_init();
curl_setopt($channel, CURLOPT_URL, "$this->baseURL/pendingfiles.json");
curl_setopt($channel, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($channel, CURLOPT_POST, true);
curl_setopt($channel, CURLOPT_POSTFIELDS, $data);
curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authorization: BASIC " . base64_encode($this->api_key . ":xxx"),
));
curl_setopt($channel, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($channel);

并得到响应:

"MESSAGE":"表单域'文件'不包含有效文件","STATUS":"错误"

【问题讨论】:

  • $filePath 临时文件名是否像 CI4 中的 $file->getTempName() ?

标签: php json file curl


【解决方案1】:

问题出在 ZendFramework 中。 以ZF1形式上传后获取文件路径的正确方法是:

$file = $form->getElement('pendingFileAttachments')->getTransferAdapter()->getFileInfo();
$file['tmp_name'] // this is filepath

就是这样。

【讨论】:

    猜你喜欢
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 2019-02-16
    • 2021-09-18
    • 1970-01-01
    • 2018-03-07
    相关资源
    最近更新 更多