Skip to content

Commit ccbb10f

Browse files
committed
added upload
1 parent fbe8e6e commit ccbb10f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class UpdateMetadataError extends SmashdocsError{}
1717
class OpenError extends SmashdocsError{}
1818
class ExportError extends SmashdocsError{}
1919

20+
function endswith($string, $test) {
21+
$strlen = strlen($string);
22+
$testlen = strlen($test);
23+
if ($testlen > $strlen) return false;
24+
return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
25+
}
26+
2027
class Smashdocs {
2128

2229
function __construct($portal_url, $client_id, $client_key, $verbose=0) {
@@ -290,7 +297,11 @@ function upload_document($fn) {
290297
"sectionHistory" => true
291298
);
292299

293-
$url = $this->partner_url . "/partner/imports/word/upload";
300+
if (endswith($fn, '.docx')) {
301+
$url = $this->partner_url . "/partner/imports/word/upload";
302+
} else {
303+
$url = $this->partner_url . "/partner/imports/sdxml/upload";
304+
}
294305

295306
$client = new Client();
296307
$fp = fopen($fn, 'rb');

scripts/upload.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
$client_id = $_SERVER['SMASHDOCS_CLIENT_ID'];
66
$client_key = $_SERVER['SMASHDOCS_CLIENT_KEY'];
77

8-
$sd = new Smashdocs($partner_url, $client_id, $client_key, 1);
8+
$sd = new Smashdocs($partner_url, $client_id, $client_key, 0);
99

1010
$result = $sd->upload_document('test.docx');
1111
print_r($result) . "\n";
12+
$result = $sd->upload_document('test_sdxml_large.zip');
13+
print_r($result) . "\n";
1214
?>

test_sdxml_large.zip

2.33 MB
Binary file not shown.

0 commit comments

Comments
 (0)