uploadFile API

uploadFile API

Hey Everyone,

I'm getting a "Couldn't open file" error when trying to upload a file to a custom module in zoho. I tested this yesterday and it worked fine however when testing today it doesn't work. I haven't changed the code so I'm not sure what the deal is. If anyone has any insight on this I would greatly appreciate it. Been testing and debugging this for hours..

  1.                         $FileName = $_FILES['File']['name'];
  2. $FileSize = $_FILES['File']['size'];
  3. $FileTmp  = $_FILES['File']['tmp_name'];
  4. $FileType = $_FILES['File']['type'];

  5. $postFields = array("id"=>$AgentId[0], "content"=>curl_file_create($FileName,"application/pdf",basename($FileName)));
  6. echo "Filename: " . $FileName . "<br>" . "FileSize: " . $FileSize . "<br>" . "FileTmp: " . $FileTmp . "<br>" . "FileType: " . $FileType;

  7. $ch = curl_init();
  8. curl_setopt($ch, CURLOPT_HEADER, 0);
  9. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  11. curl_setopt($ch, CURLOPT_URL, "https://crm.zoho.com/crm/private/xml/CustomModule10/uploadFile?authtoken=--myauth--&scope=crmapi");
  12. curl_setopt($ch, CURLOPT_POST, true);
  13. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  14. $response = curl_exec($ch);
  15. echo curl_getinfo($ch) . '<br/>';
  16. echo curl_errno($ch) . '<br/>';
  17. echo curl_error($ch) . '<br/>';
  18. echo $response;
  19. curl_close($ch);


  20. if (!function_exists('curl_file_create')) {
  21.     function curl_file_create($FileName, $mimetype = '', $postname = '') {
  22.         return "@$FileName;filename="
  23.             . ($postname ?: basename($FileName))
  24.             . ($mimetype ? ";type=$mimetype" : '');
  25.     }
  26. }
Response from website:
Filename: Scope.pdf
FileSize: 539651
FileTmp: /tmp/phpxyCcQS
FileType: application/pdf
Error Code(26)
couldn't open file "Scope.pdf"