m.qayyum
m.qayyum

Reputation: 411

Command line curl to PHP curl and PHP curl returning blank file

I want to convert a .html file to .epub file by using API from this website https://ebookglue.com/docs They have example in Command line curl, but I want to use PHP curl and don't know how to convert this correctly to PHP curl

Here is command line curl

curl -o converted.epub \
-F "token=your-api-key" \
-F "[email protected]" \
https://ebookglue.com/convert

Here what I have got so far, it is not working and returning blank dat.epub file

$token  =    "token";
$tmpfile = $_FILES['file']['tmp_name'];
$filename = basename($_FILES['file']['name']);

$data = array(
    'token'  => $token,
    'file'          =>  '@'.$tmpfile.';filename='.$filename,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ebookglue.com/convert");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
$out = curl_exec($ch);
curl_close($ch);
$fp = fopen('data.epub', 'w');
fwrite($fp, $out);
fclose($fp);

Upvotes: 0

Views: 258

Answers (1)

vidario
vidario

Reputation: 479

You didn't set the POST option:

curl_setopt($ch, CURLOPT_POST, 1);

If that doesn't work:

I notice you're connecting via SSL. Unless you have all the certificates sorted, try this

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

But read up on what this means.

Upvotes: 2

Related Questions