Sending a file via HTTP PUT in PHP

后端 未结 5 1619
孤独总比滥情好
孤独总比滥情好 2020-12-28 22:53

I\'ve been struggling for several hours trying to figure out how to get this work. I\'m trying to send a file via HTTP-PUT to an eXist db. There is user authentication for

5条回答
  •  萌比男神i
    2020-12-28 23:37

    Aha! After a little "rubber ducking" with the grumpy dwarf stuffed doll on my desk here, I figured out the solution:

            $data = file_get_contents($tmpFile);
             $params = array(
                 'http' => array(
                     'method' => 'PUT',
                     'header' => "Authorization: Basic " . base64_encode($this->ci->config->item('ws_login') . ':' . $this->ci->config->item('ws_passwd')) . "\r\nContent-type: text/xml\r\n",
                     'content' => file_get_contents($tmpFile)
                 )
             );
             $ctx = stream_context_create($params);
             $response = @file_get_contents($url, false, $ctx);
    
             return ($response == '');
    

提交回复
热议问题