doulao1934 2015-09-28 09:20
浏览 48
已采纳

团队合作api,如何发送文件?

I'm using ZF1 form to take data and cURL to send them to Teamwork API. I try create new task on task list and it's OK. Problem is, when I try to attach the file, the server response is:

"MESSAGE":"Temp file reference not found","STATUS":"Error"

What should I do?

Please help.

My form:

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

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

And I just get from $_POST 'pendingFileAttachments' and try to encode in json and sent. Probably is need to get file not just file name, is this true?

Thank from help in advance.

EDIT:

So, I've found that I should first upload the file to Teamwork API and after use uploaded file ref in create task POST cURL function.

Now I have uploaded file on server's hard disk and in my php script i use "realpath" to finde that is really exist and feel well.

Than I use this code:

$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);

and get response:

"MESSAGE":"The form field 'file' did not contain a valid file","STATUS":"Error"

  • 写回答

1条回答 默认 最新

  • douguizhuang8276 2015-10-12 13:22
    关注

    The problem was in ZendFramework. Properly way to get file path after upload in ZF1 form is:

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

    That's all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退