From 01ebc17a5dadbc8bf631e84b02d704e9bcda3f52 Mon Sep 17 00:00:00 2001 From: Ryuya Yanagi <57742720+apple-yagi@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:14:34 +0900 Subject: [PATCH 1/6] Fix phpdoc for ResultFile's getContents function (#65) --- lib/ConvertApi/ResultFile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ConvertApi/ResultFile.php b/lib/ConvertApi/ResultFile.php index e84ec62..9ac2be6 100644 --- a/lib/ConvertApi/ResultFile.php +++ b/lib/ConvertApi/ResultFile.php @@ -36,7 +36,7 @@ function getFileSize() } /** - * @return string Converted file contents + * @return false|string Converted file contents */ function getContents() { @@ -57,4 +57,4 @@ function save($path) return ConvertApi::client()->download($this->getUrl(), $path); } -} \ No newline at end of file +} From 234334ea3fee5ae6cbcf4729e69fce7bb02f76ea Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 15 Apr 2025 15:05:35 +0300 Subject: [PATCH 2/6] Create vanilla_php.php --- examples/vanilla_php.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/vanilla_php.php diff --git a/examples/vanilla_php.php b/examples/vanilla_php.php new file mode 100644 index 0000000..be91435 --- /dev/null +++ b/examples/vanilla_php.php @@ -0,0 +1,22 @@ + new CurlFile($file_path)), 'storefile' => 'false'); + $result = curl_exec($curl); + if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) { + file_put_contents("result.pdf", $result); + } else { + print("Server returned error:\n".$result."\n"); + } + } else { + print('File does not exist: '.$file_path."\n"); + } +?> From 54357b60771f8919bded7dfe8fadde8e9a60a3d1 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Mon, 2 Jun 2025 15:43:10 +0300 Subject: [PATCH 3/6] Bearer authentication --- examples/vanilla_php.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/vanilla_php.php b/examples/vanilla_php.php index be91435..89d2855 100644 --- a/examples/vanilla_php.php +++ b/examples/vanilla_php.php @@ -8,7 +8,8 @@ curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/octet-stream')); - curl_setopt($curl, CURLOPT_URL, "https://v2.convertapi.com/convert/docx/to/pdf?secret=".$secret); + curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$secret)); + curl_setopt($curl, CURLOPT_URL, "https://v2.convertapi.com/convert/docx/to/pdf"); curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => new CurlFile($file_path)), 'storefile' => 'false'); $result = curl_exec($curl); if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) { From 93c668da254bc8ba81dde3c6f8dc377b83a58740 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Mon, 2 Jun 2025 16:26:43 +0300 Subject: [PATCH 4/6] Update vanilla_php.php --- examples/vanilla_php.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/vanilla_php.php b/examples/vanilla_php.php index 89d2855..cda4a55 100644 --- a/examples/vanilla_php.php +++ b/examples/vanilla_php.php @@ -1,22 +1,30 @@ new CurlFile($file_path)), 'storefile' => 'false'); + $headers = array( + 'Accept: application/octet-stream', + 'Authorization: Bearer ' . $secret + ); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + $postData = array( + 'file' => new CURLFile($file_path), + 'storefile' => 'false' + ); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + print("Converting...\n"); $result = curl_exec($curl); if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) { file_put_contents("result.pdf", $result); } else { - print("Server returned error:\n".$result."\n"); - } + print("Server returned error:\n".$result."\n"); +} } else { print('File does not exist: '.$file_path."\n"); } From 80b4242124ab73301f10abf9460ee8da3d56d505 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Mon, 2 Jun 2025 17:14:55 +0300 Subject: [PATCH 5/6] Update vanilla_php.php --- examples/vanilla_php.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/vanilla_php.php b/examples/vanilla_php.php index cda4a55..2aa5064 100644 --- a/examples/vanilla_php.php +++ b/examples/vanilla_php.php @@ -1,6 +1,6 @@ Date: Tue, 3 Jun 2025 09:52:49 +0300 Subject: [PATCH 6/6] Update vanilla_php.php --- examples/vanilla_php.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vanilla_php.php b/examples/vanilla_php.php index 2aa5064..bdf792c 100644 --- a/examples/vanilla_php.php +++ b/examples/vanilla_php.php @@ -1,6 +1,6 @@