forked from cloudconvert/cloudconvert-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.serverside.callback.php
More file actions
48 lines (35 loc) · 1.24 KB
/
sample.serverside.callback.php
File metadata and controls
48 lines (35 loc) · 1.24 KB
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
42
43
44
45
46
47
48
<?php
/*
* Converts the file input.png server side to output.pdf
*
*/
// for testing it could be helpful...
ini_set('display_errors', 1);
require_once 'CloudConvert.class.php';
// if callback was triggered by CloudConvert
if (!empty($_REQUEST['callback'])) {
// conversion should be finished!
// see: https://cloudconvert.org/page/api#callback
$process = CloudConvert::useProcess($_REQUEST['url']);
// check the status
$status = $process -> status();
if ($status -> step == 'finished') {
// it worked. download it
$process -> download('output.pdf');
// update the DB etc
} else {
// it failed. get the error message: $status -> message;
}
// maybe delete process from CloudConvert
// $process -> delete();
} else {
// start the conversion
// insert your API key here
$apikey = "";
$process = CloudConvert::createProcess("png", "pdf", $apikey);
// insert (public) URLs here
$process -> setOption("callback", "http://_INSERT_PUBLIC_URL_TO_THIS_FILE_/sample.serverside.callback.php?callback=true");
$process -> uploadByUrl("http://_INSERT_PUBLIC_URL_TO_INPUT_FILE_/input.png", "input.png", "pdf");
echo "Conversion was started in background :-)";
}
?>