如何使用php://内存文件句柄执行cURL PUT请求?

Cli*_*ote 4 php curl filehandle

我正在使用第三方PHP类来访问API,它有以下代码:

$fh = fopen('php://memory', 'w+');
fwrite($fh, $xml);
rewind($fh);
$ch = curl_init($req->to_url() );
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $fh);
Run Code Online (Sandbox Code Playgroud)

在最后一行,即这一行:

curl_setopt($ch, CURLOPT_INFILE, $fh);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

警告:curl_setopt()[function.curl-setopt]:不能将MEMORY类型的流表示为STDIO FILE*

我究竟做错了什么?

Gor*_*don 13

您的内存文件句柄仅对写入(w +)开放.添加阅读,例如尝试设置rw+文件句柄.

另一种方法是使用php://temp而不是内存.如果没有足够的可用内存,那将写入临时文件.