我正在尝试使用API,我尝试使用多个图像但是使用单个图像api代码工作正常但是当我使用以下代码处理多个图像时,我收到错误(检查错误日志)。我不知道如何解决这个问题,是的,我已经尝试使用
在stackoverflow上解决了这个问题$field_string = http_build_query($fields);
并在
中使用相同的内容 curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string);
但这并没有解决问题
我的代码:
<?php
$filename = $_GET['filesx'];
//set POST variables
$url = 'http://c.docverter.com/convert';
$fields = array('from' => 'html',
'to' => 'pdf',
'input_files[]' => "@/".realpath('example_files/'.$filename).";type=text/html; charset=UTF-8",
//'other_files[]' => "@/".realpath('example_files/dasd.png'), works
'other_files' => array(
'@/'.realpath('example_files/182078images.jpg'),
'@/'.realpath('example_files/dasd.png')
)
);
//$field_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$finalx = strstr($filename , '.html', true);
$fp = fopen('uploads/'.$finalx.'.pdf', 'w');
fwrite($fp, $result);
fclose($fp);
echo '<script type="text/javascript">
window.location = "http://docs.google.com/viewer?url=justchecka.com/'.$finalx.'.pdf&embedded=true"
</script>';
错误日志:
[19-Mar-2017 19:49:37 Etc/GMT] PHP Notice: Array to string conversion in /home/markdown_to_pdf.php on line 23
[19-Mar-2017 19:49:37 Etc/GMT] PHP Stack trace:
[19-Mar-2017 19:49:37 Etc/GMT] PHP 1. {main}() /home/markdown_to_pdf.php:0
[19-Mar-2017 19:49:37 Etc/GMT] PHP 2. curl_setopt() /home/markdown_to_pdf.php:23