Skip to content

Commit 234334e

Browse files
authored
Create vanilla_php.php
1 parent 01ebc17 commit 234334e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

examples/vanilla_php.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
$file_path = 'C:\my_file.docx';
3+
$secret = 'XXXXXXXXXXXXXXXX';
4+
5+
if (file_exists($file_path)) {
6+
$curl = curl_init();
7+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
8+
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
9+
curl_setopt($curl, CURLOPT_POST, true);
10+
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/octet-stream'));
11+
curl_setopt($curl, CURLOPT_URL, "https://v2.convertapi.com/convert/docx/to/pdf?secret=".$secret);
12+
curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => new CurlFile($file_path)), 'storefile' => 'false');
13+
$result = curl_exec($curl);
14+
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
15+
file_put_contents("result.pdf", $result);
16+
} else {
17+
print("Server returned error:\n".$result."\n");
18+
}
19+
} else {
20+
print('File does not exist: '.$file_path."\n");
21+
}
22+
?>

0 commit comments

Comments
 (0)