Sending a file via HTTP PUT in PHP

后端 未结 5 1638
孤独总比滥情好
孤独总比滥情好 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条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-28 23:39

    function _publish($service, $doc) {
        $params = array(
            'http' => array(
                'method' => 'PUT'));
        $context = stream_context_create($params);
        $fp = fopen($service, 'rb', false, $context);
        $response = fwrite($fp,file_get_contents($doc));
        if ($response === false) {
            return false;
        }
        // Pull out the status code from the header
        $metaData = stream_get_meta_data($fp);
        preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/", $metaData['wrapper_data'][0], $matches);
        $code = end($matches[1]);
        if ($code == 200) {
            return true;
        } else {
            return false;
        }
    }
    

    from http://www.littlehart.net/atthekeyboard/2008/01/11/how-to-http-put-a-file-somewhere-using-php/

提交回复
热议问题