[英]How to do cURL PUT requests with a php://memory file handle?
I'm using a 3rd party PHP class to access an API, it has got the following code: 我正在使用第三方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);
On the last line, ie this one: 在最后一行,即这一行:
curl_setopt($ch, CURLOPT_INFILE, $fh);
I'm getting the error: 我收到错误:
Warning: curl_setopt() [function.curl-setopt]: cannot represent a stream of type MEMORY as a STDIO FILE* 警告:curl_setopt()[function.curl-setopt]:不能将MEMORY类型的流表示为STDIO FILE *
What am I doing wrong? 我究竟做错了什么?
Your Memory File Handle is only open for writing (w+). 您的内存文件句柄仅对写入(w +)开放。 Add reading, eg try to set rw+
for the file handle. 添加读数,例如尝试为文件句柄设置rw+
。
An alternative would be to use php://temp
instead of memory. 另一种方法是使用php://temp
而不是内存。 That would write to a temporary file if there isn't enough memory available. 如果没有足够的可用内存,那将写入临时文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.