php - POST with curl not working. But can be done with form -
want post request site: https://api.telegram.org/mytoken/sendphoto
created form that:
<!doctype html> <html> <body> <form action="http://api.telegram.org/mytoken/sendphoto" method="post" enctype="multipart/form-data"> select image upload: <input type="file" name="photo" id="photo"> <input type="hidden" value="108432389" name="chat_id"> <input type="submit" value="upload image" name="submit"> </form> </body> </html>
it works good. following headers sent:
-----------------------------25522111424583 content-disposition: form-data; name="photo"; filename="untitled.png" content-type: image/png png
i write following script curl:
<?php $ch = curl_init('https://api.telegram.org/token/sendphoto'); $cfile = new curlfile('ur.png','image/png','photo'); $data = array('chat_id' => '108432389', 'photo' => $cfile); curl_setopt($ch, curlopt_post,1); curl_setopt($ch, curlopt_postfields, $data); $res=curl_exec($ch); echo $res; ?>
but it's not working, wrong?
it solved.
line:
$cfile = new curlfile('ur.png','image/png','photo');
should change :
$cfile = new curlfile(realpath('ur.png'),'image/png','photo.png');
Comments
Post a Comment