How to make cURL PUT requests using php: // file descriptor?

I use a third-party PHP class to access the API, it has the following code:

$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); 

In the last line, that is:

 curl_setopt($ch, CURLOPT_INFILE, $fh); 

I get an error message:

Warning: curl_setopt () [function.curl-setopt]: cannot represent a stream of type MEMORY as a STDIO FILE *

What am I doing wrong?

+4
source share
1 answer

Your folder with the memory file is open for writing only (w +). Add a reading, for example. try setting rw+ for the file descriptor.

An alternative would be to use php://temp instead of memory. This will be written to a temporary file if access to memory is insufficient.

+12
source

All Articles