Sending a file via HTTP PUT in PHP

后端 未结 5 1615
孤独总比滥情好
孤独总比滥情好 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:34

    CURL works for me. Here is snippet from my code,

                    $handle = curl_init ($server_url);
    
                    if ($handle)
                    {
                        // specify custom header
                        $customHeader = array(
                            "Content-type: $file_type"
                        );
                        $curlOptArr = array(
                            CURLOPT_PUT => TRUE,
                            CURLOPT_HEADER => TRUE,
                            CURLOPT_HTTPHEADER => $customHeader,
                            CURLOPT_INFILESIZE => $file_size,
                            CURLOPT_INFILE => $file,
                            CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                            CURLOPT_USERPWD => $user . ':' . $password,
                            CURLOPT_RETURNTRANSFER => TRUE
                        );
                        curl_setopt_array($handle, $curlOptArr);
                        $ret = curl_exec($handle);
                        $errRet = curl_error($handle);
                        curl_close($handle);
    

    EDIT: Just updated my code. I don't use authentication myself so this is not tested.

提交回复
热议问题