Skip to content

Commit acc34d3

Browse files
committed
updated
1 parent 11a148e commit acc34d3

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Diff for: api.php

+49
Original file line numberDiff line numberDiff line change
@@ -304,5 +304,54 @@ function new_document() {
304304
$result = (array) json_decode($out);
305305
return $result;
306306
}
307+
308+
function upload_document($fn) {
309+
310+
$headers = array(
311+
"x-client-id: ". $this->client_id,
312+
"authorization: ". "Bearer " . $this->gen_token()
313+
);
314+
315+
$user_data = array(
316+
"email" => "[email protected]",
317+
"firstname" => "Andreas",
318+
"lastname" => "Jung",
319+
"userId" => "ajung",
320+
"company" => "ZOPYX"
321+
);
322+
323+
$data = array(
324+
"user" => $user_data,
325+
"title" => "my title",
326+
"description" => "my description",
327+
"groupId" => "xxxx",
328+
"userRole" => "editor",
329+
"sectionHistory" => true
330+
);
331+
332+
333+
334+
$url = $this->partner_url . "/partner/imports/word/upload";
335+
336+
337+
$fp = fopen($fn, 'rb');
338+
$ch = curl_init();
339+
curl_setopt_array($ch, array(
340+
CURLOPT_URL => $url,
341+
CURLOPT_INFILE => $fp,
342+
CURLOPT_INFILESIZE => filesize($fn),
343+
CURLOPT_POST => 1,
344+
CURLOPT_HTTPHEADER => $headers,
345+
CURLOPT_POSTFIELDS => json_encode($data),
346+
CURLOPT_RETURNTRANSFER =>true,
347+
CURLINFO_HEADER_OUT => true,
348+
CURLOPT_VERBOSE => $this->verbose
349+
)
350+
);
351+
$out = $this->check_http_result($ch, 200, 'CreationFailed');
352+
curl_close ($ch);
353+
$result = (array) json_decode($out);
354+
return $result;
355+
}
307356
}
308357
?>

Diff for: test.docx

9.69 KB
Binary file not shown.

Diff for: upload.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
include 'api.php';
3+
4+
$partner_url = $_SERVER['SMASHDOCS_PARTNER_URL'];
5+
$client_id = $_SERVER['SMASHDOCS_CLIENT_ID'];
6+
$client_key = $_SERVER['SMASHDOCS_CLIENT_KEY'];
7+
8+
$sd = new Smashdocs($partner_url, $client_id, $client_key, 1);
9+
10+
$result = $sd->upload_document('test.docx');
11+
print_r($result) . "\n";
12+
?>

0 commit comments

Comments
 (0)