|
1 | 1 | <?php |
2 | | - $file_path = 'C:\my_file.docx'; |
3 | | - $secret = 'XXXXXXXXXXXXXXXX'; |
4 | | - |
| 2 | + $file_path = 'jmeter-docx.docx'; |
| 3 | + $secret = 'BF1A7s5ODYhxBfVelFLKU2OzSgoJAt0a'; |
| 4 | + |
5 | 5 | if (file_exists($file_path)) { |
6 | 6 | $curl = curl_init(); |
| 7 | + curl_setopt($curl, CURLOPT_URL, 'https://v2.convertapi.com/convert/docx/to/pdf'); |
7 | 8 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
8 | 9 | curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); |
9 | 10 | 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"); |
14 | 22 | $result = curl_exec($curl); |
15 | 23 | if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) { |
16 | 24 | file_put_contents("result.pdf", $result); |
17 | 25 | } else { |
18 | | - print("Server returned error:\n".$result."\n"); |
19 | | - } |
| 26 | + print("Server returned error:\n".$result."\n"); |
| 27 | +} |
20 | 28 | } else { |
21 | 29 | print('File does not exist: '.$file_path."\n"); |
22 | 30 | } |
|
0 commit comments