将curl命令转换为PHP以获得csv->;Excel转换器

将curl命令转换为PHP以获得csv->;Excel转换器,php,curl,Php,Curl,看起来很简单,但我无法在PHP中实现这一点 curl -F files[]=@myfile.csv 'https://www.rebasedata.com/api/v1/convert?outputFormat=xlsx&errorResponse=zip' -o output.zip myfile.csv是要转换的数据文件 output.zip是包含Excel文件的响应 这是本网站提供的csv到Excel转换服务 有人能帮忙吗?试试下面的代码 set_time_limit(0);

看起来很简单,但我无法在PHP中实现这一点

curl -F files[]=@myfile.csv 'https://www.rebasedata.com/api/v1/convert?outputFormat=xlsx&errorResponse=zip' -o output.zip
myfile.csv是要转换的数据文件

output.zip是包含Excel文件的响应

这是本网站提供的csv到Excel转换服务

有人能帮忙吗?

试试下面的代码

set_time_limit(0);

// output file
$fp = fopen('output.zip', 'w+');

$ch = curl_init('https://www.rebasedata.com/api/v1/convert?outputFormat=xlsx&errorResponse=zip');
curl_setopt($ch, CURLOPT_POST, true);
// Adding file to request
curl_setopt($ch, CURLOPT_POSTFIELDS, ['files' => curl_file_create('myfile.csv')]);
// For returning response data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
fwrite($fp, $data);

curl_close($ch);
fclose($fp);

谢谢你,尼基塔,但它不起作用。我正在运行来自xampp的代码,并在Web主机上进行了尝试。它创建了output.zip,但它是一个空的zip文件。仍然不工作。现在,它创建了一个26字节的文件,而不是一个打开的0字节文件。说“这是一个无效的zip文件”谢谢你Nikita。我感谢你的帮助。