4

我正在使用第 3 方 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);

在最后一行,即这一行:

curl_setopt($ch, CURLOPT_INFILE, $fh);

我收到错误:

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

我究竟做错了什么?

4

1 回答 1

13

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

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

于 2011-07-27T09:29:06.957 回答