Upload file with curl php by custom header -



headers sends programs adress:

--55ae49448a20c content-disposition: form-data; name="chat_id" content-length: 9  108432389 --55ae49448a20c content-disposition: form-data; name="photo"; filename="untitled.png" content-length: 16252 content-type: image/png   png 

i want post 2 varibles (chat_id) , (photo) following code.
attempted code:

    <?php $params  = "content-disposition: form-data; name=\"chat_id\"\r\n"     . "content-length: 9\r\n\r\n"     . "\r\n"     . "content-disposition: form-data; name=\"photo\"; filename=\"untitled.png\"\r\n"     . "content-length: ".filesize("untitled.png")."\r\n"     . "content-type: image/png\r\n\r\n"     . file_get_contents("untitled.png"); $request_headers    = array(); $request_headers[]  = 'content-length: ' . strlen($params); $url     = 'http://example.com'; $ch = curl_init($url); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $params); curl_setopt($ch, curlopt_proxy, '127.0.0.1:8888'); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_httpheader, $request_headers); $reply = curl_exec($ch); ?> 

is there other way !?
attempted code gives me 400 bad gatway error..

that's totally unnecessary. you're doing way curl can far better (and properly) itself.

$post = array(     'chat_id' => 108432389,     'photo' => '@untitled.jpg' ); curl_setopt($ch, curlopt_postfields, $post); 

old-school php curl used @ in value field signify file uploaded. newer versions use curlfile instead.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -