whyleyc / zamzar-php

Simple PHP script to use the Zamzar file conversion API
MIT License
1 stars 1 forks source link

It's not work on localhost #1

Closed ask2rg closed 3 years ago

ask2rg commented 3 years ago

i have try to run the code but its not work on my local environment (wamp localhost)

line:43 $body = curl_exec($ch);

not get anything in body i also try this : // Execute cURL $ch = curl_init(); // Init curl curl_setopt($ch, CURLOPT_URL, $endpoint.'/jobs'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //added $body = curl_exec($ch); curl_close($ch);

WampServer Version 3.0.4 64bit i need to use zamzar api localy for devlopement

whyleyc commented 3 years ago

Thanks for using the script @ask2rg

Please can you clarify what you mean by "not work on my local environment"? Do you mean that you are trying to submit a file hosted at "localhost" for conversion by the API, or that the script is throwing an error when run?

If you can paste any specific error messages that you are seeing along with the exact code used to recreate them that would be helpful.

ask2rg commented 3 years ago

yes i am test zamzar api locally on WAMP server sourceFile and php file both in same folder localy

no error appear actually not getting any response from zamzar

well i might find solution go to next step but there are also an issue that its return target_files , by sending a GET request to the jobs/ID endpoint.

i use this code :

$endpoint = "https://sandbox.zamzar.com/v1/jobs"; $apiKey = "79XXXXXXXX5"; $sourceFilePath = "sample.pdf"; $targetFormat = "txt";

// Since PHP 5.5+ CURLFile is the preferred method for uploading files if(function_exists('curl_file_create')) { $sourceFile = curl_file_create(realpath($sourceFilePath)); } else { $sourceFile = '@' . realpath($sourceFilePath); }

$postData = array( "source_file" => $sourceFile, "target_format" => $targetFormat );

$ch = curl_init(); // Init curl curl_setopt($ch, CURLOPT_URL, $endpoint); // API endpoint curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); // Enable the @ prefix for uploading files curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response as a string curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":"); // Set the API key as the basic auth username curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $body = curl_exec($ch); curl_close($ch);

$response = json_decode($body, true);

echo "Response:\n---------\n"; print_r($response);

$jobID = $response['id']; $endpoint = "https://sandbox.zamzar.com/v1/jobs/".$jobID; $apiKey = "7XXXXXXXXXXXXXXX5";

$ch = curl_init(); // Init curl curl_setopt($ch, CURLOPT_URL, $endpoint); // API endpoint curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response as a string curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":"); // Set the API key as the basic auth username curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $body = curl_exec($ch); curl_close($ch);

$job = json_decode($body, true);

echo "Job:\n----\n"; print_r($job);

ask2rg commented 3 years ago

hi thanks for your support, your script is working fine on lamp, but may need some changes when use on WAMP

i moved one step further but now i facing issue to download output file locally for now i use this code : https://github.com/ask2rg/zamzar-php/blob/ravi-wamp/zamzar-sample.php
but line 79 and 80 display error

alt text

ask2rg commented 3 years ago

All solved

Thanks @whyleyc providing the script and support, now you can close the issue.

please assign task to me so that i will send pull request for working demo of wamp, i am new to GitHub and PHP

Thanks again :)