Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*********************************************************************************
- ** This waits for the Zendesk Schedule report call and then downloads the **
- ** file your Local server for you to act on with other functions or programs **
- *********************************************************************************/
- //We're gonna email the XML we receive for testing purposes. Here are our details.
- $to = ''; //Your email address
- $subject = 'Testing .csv export';
- $xmlDoc = new DOMDocument();
- //Reads the POST from Zendesk
- $encodedMessage = file_get_contents("php://input");
- //loads the XML
- $xmlDoc->loadXML($encodedMessage);
- //gets the URL from the Zendesk XML callback
- $url = $xmlDoc->getElementsByTagName("url")->item(0)->nodeValue;
- //give it a admins user name and password to download it
- $username = ''; //Add your admin username
- $password = ''; //Add your admin password (or token if username is adjusted accordingly)
- //Grabs the path name, splits for the file name
- $csvName = parse_url($url, PHP_URL_PATH);
- $csvNamePath = explode('/', $csvName);
- $pathCSVsize = sizeof($csvNamePath)-1;
- $csvFileName = $csvNamePath[$pathCSVsize];
- //Email a copy of the url for diagnostic purposes
- mail($to, $subject, $csvFileName);
- transport($url, $username, $password, $csvFileName);
- //takes the url and file name downloads to your local server
- function transport($url, $username, $password, $csvFileName)
- {
- //$headers = array('Content-type: application/zip');
- $cobj = curl_init();
- $csvContent = fopen($csvFileName,'w');
- curl_setopt($cobj, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($cobj, CURLOPT_USERPWD, $username . ":" . $password);
- curl_setopt($cobj, CURLOPT_URL, $url);
- //curl_setopt($cobj, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($cobj, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($cobj, CURLOPT_FILE, $csvContent);
- curl_exec($cobj);
- curl_close($cobj);
- }
- exit;
- ?>
Add Comment
Please, Sign In to add comment