PHP设置多部分或表单数据

PHP设置多部分或表单数据,php,Php,我正在尝试使用以下代码处理html文件,但在使用PHPAPI时遇到了一个问题。我已经在服务器上准备好了这些文件,但是我不知道如何使用下面的代码设置多部分/表单数据来进行转换。假设我在同一个文件夹中有一个html文件,我如何在下面的代码中使用它进行转换 转换代码: <?php //set POST variables $fields = array('from' => 'markdown', 'to' => 'pdf', 'input_files

我正在尝试使用以下代码处理html文件,但在使用PHPAPI时遇到了一个问题。我已经在服务器上准备好了这些文件,但是我不知道如何使用下面的代码设置多部分/表单数据来进行转换。假设我在同一个文件夹中有一个html文件,我如何在下面的代码中使用它进行转换

转换代码:

<?php
//set POST variables 
$fields = array('from' => 'markdown',
        'to' => 'pdf',
        'input_files[]' => "@/".realpath('markdown.md').";type=text/x-markdown; charset=UTF-8"
        );

//open connection
$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); //needed so that the $result=curl_exec() output is the file and isn't just true/false

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

?>

自PHP 5.5以来,用于指定文件路径的
@
格式不再有效,该值将作为原始字符串发送。相反,尝试一下。此外,无论版本如何,也不要忘记将
CURLOPT_POST
变量设置为true。此代码还假定您对正在上载的文件具有读取权限

<?php
$url = 'http://c.docverter.com/convert';
$fields = [
    'from' => 'markdown',
    'to' => 'pdf',
    'input_files[]' => (PHP_VERSION_ID < 50500) ? '@' . realpath('markdown.md') : curl_file_create('markdown.md')
];
$result_file = 'uploads/result.pdf';

//open connection
$ch = curl_init($url);

curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => $fields,
    CURLOPT_RETURNTRANSFER => true
]);
$result = curl_exec($ch);
curl_close($ch);
file_put_contents($result_file, $result);

你忘了吗
curl\u setopt($ch,CURLOPT\u POST,1)?另外,您使用的PHP版本是什么?@miken32我使用的是5.4版本。我不知道如何使用上述代码在同一文件夹中使用html文件。我只是想知道如何使用它。