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
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?
$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.
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"