开发者

HTML + PHP - how to send uploaded file to server

开发者 https://www.devze.com 2023-03-09 22:53 出处:网络
I want to use a PHP as a proxy to upload files to server. How can i send the uploaded files to a se开发者_开发知识库rver together with Basic Authorization header?Is PECL ssh2 an option?If it is, then

I want to use a PHP as a proxy to upload files to server. How can i send the uploaded files to a se开发者_开发知识库rver together with Basic Authorization header?


Is PECL ssh2 an option? If it is, then you won't need the authentication header as you can do authentication through ssh. If not, then you can use cURL to set the header and send the information to a script on another server that is designed to receive the upload (and under the http authentication requirements).


Use cURL and Basic access authentication headers:

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, "https://example.com/path/"); 
curl_setopt($curl, CURLOPT_PORT , 80);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
curl_setopt($curl, CURLOPT_HTTPHEADER,
    array('Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==')); 

cURL provides other options like CURLOPT_FILE that can help your specific case.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号