我有一个在终端工作正常的卷曲脚本。PHP:卷曲脚本工作,但不是在PHP文件
curl -XPOST \
-F "[email protected]/www/myfile.wav;type=audio/wav" \
-H 'Authorization: Bearer $MY_TOKEN' \
'https://myurl'
我已经试过这种方式在我的PHP文件,
<?php
$url = "https://myurl";
$key = "myKey";
$path = "/var/www/";
$fileName = "myfile.wav";
$data['file']= "@".$path.$fileName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Authorization: Bearer $key"));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
我得到一个错误,从服务器。似乎我没有按照服务器的要求提出请求。我错过了PHP脚本中的任何东西吗?
没有工作:( –
你收到什么错误?“不起作用”真的不会帮助任何人回答你的问题。你能详细说明错误吗? –
服务器刚刚返回“en error occurred”。它是我正在使用的第三方服务。当我运行curl脚本时服务器正确返回。 –