Skip to content

Commit 93c668d

Browse files
authored
Update vanilla_php.php
1 parent 54357b6 commit 93c668d

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

examples/vanilla_php.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
<?php
2-
$file_path = 'C:\my_file.docx';
3-
$secret = 'XXXXXXXXXXXXXXXX';
4-
2+
$file_path = 'jmeter-docx.docx';
3+
$secret = 'BF1A7s5ODYhxBfVelFLKU2OzSgoJAt0a';
4+
55
if (file_exists($file_path)) {
66
$curl = curl_init();
7+
curl_setopt($curl, CURLOPT_URL, 'https://v2.convertapi.com/convert/docx/to/pdf');
78
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
89
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
910
curl_setopt($curl, CURLOPT_POST, true);
10-
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/octet-stream'));
11-
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$secret));
12-
curl_setopt($curl, CURLOPT_URL, "https://v2.convertapi.com/convert/docx/to/pdf");
13-
curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => new CurlFile($file_path)), 'storefile' => 'false');
11+
$headers = array(
12+
'Accept: application/octet-stream',
13+
'Authorization: Bearer ' . $secret
14+
);
15+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
16+
$postData = array(
17+
'file' => new CURLFile($file_path),
18+
'storefile' => 'false'
19+
);
20+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
21+
print("Converting...\n");
1422
$result = curl_exec($curl);
1523
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
1624
file_put_contents("result.pdf", $result);
1725
} else {
18-
print("Server returned error:\n".$result."\n");
19-
}
26+
print("Server returned error:\n".$result."\n");
27+
}
2028
} else {
2129
print('File does not exist: '.$file_path."\n");
2230
}

0 commit comments

Comments
 (0)