Guest User

Untitled

a guest
Dec 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2. /*********************************************************************************
  3. ** This waits for the Zendesk Schedule report call and then downloads the **
  4. ** file your Local server for you to act on with other functions or programs **
  5. *********************************************************************************/
  6.  
  7. //We're gonna email the XML we receive for testing purposes. Here are our details.
  8. $to = ''; //Your email address
  9. $subject = 'Testing .csv export';
  10.  
  11. $xmlDoc = new DOMDocument();
  12.  
  13. //Reads the POST from Zendesk
  14. $encodedMessage = file_get_contents("php://input");
  15.  
  16. //loads the XML
  17. $xmlDoc->loadXML($encodedMessage);
  18. //gets the URL from the Zendesk XML callback
  19. $url = $xmlDoc->getElementsByTagName("url")->item(0)->nodeValue;
  20.  
  21. //give it a admins user name and password to download it
  22. $username = ''; //Add your admin username
  23. $password = ''; //Add your admin password (or token if username is adjusted accordingly)
  24.  
  25. //Grabs the path name, splits for the file name
  26. $csvName = parse_url($url, PHP_URL_PATH);
  27. $csvNamePath = explode('/', $csvName);
  28. $pathCSVsize = sizeof($csvNamePath)-1;
  29. $csvFileName = $csvNamePath[$pathCSVsize];
  30.  
  31. //Email a copy of the url for diagnostic purposes
  32. mail($to, $subject, $csvFileName);
  33.  
  34. transport($url, $username, $password, $csvFileName);
  35.  
  36. //takes the url and file name downloads to your local server
  37. function transport($url, $username, $password, $csvFileName)
  38. {
  39. //$headers = array('Content-type: application/zip');
  40. $cobj = curl_init();
  41. $csvContent = fopen($csvFileName,'w');
  42.  
  43. curl_setopt($cobj, CURLOPT_SSL_VERIFYPEER, FALSE);
  44. curl_setopt($cobj, CURLOPT_USERPWD, $username . ":" . $password);
  45. curl_setopt($cobj, CURLOPT_URL, $url);
  46. //curl_setopt($cobj, CURLOPT_HTTPHEADER, $headers);
  47. curl_setopt($cobj, CURLOPT_FOLLOWLOCATION, false);
  48. curl_setopt($cobj, CURLOPT_FILE, $csvContent);
  49.  
  50. curl_exec($cobj);
  51. curl_close($cobj);
  52. }
  53.  
  54. exit;
  55.  
  56. ?>
Add Comment
Please, Sign In to add comment