bonjour,
j'essaye de télécharger un article mais je n'arrive pas à le faire.Pourriez vous me corriger ce code.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
<?php
$domain= $_GET['domain'];
 
//$locale = $_GET['locale'];
//$articleid = $_GET['article_id'];
 
// basic settings for your Zendesk
$userName = "aaa@hotmail.fr";
$apiKey = 'xxxx';
 
// upload file info
$fileName = 'myfile.txt';
$filePath = 'C:/wamp/www/myfile.txt';
$token = NULL; // set to previously returned token to upload multiple files in 1 comment
 
$url = "https://$domain.zendesk.com/api/v2/uploads.json?filename=".urlencode($fileName);
$url .= (is_null($token)) ? '' : '&token='.$token;
$file = fopen($filePath, "r");
$size = filesize($filePath);$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $userName."/token:".$apiKey);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/binary'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array($fileName => new CurlFile($filePath)));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
$output = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
fclose($file);
curl_close($ch);
 
if ($code !== 200 && $code !== 201)
{
return 'Status code returned was '.$code.'!';
}$decoded = json_decode($output);
return $decoded;
?>