2017-09-29 5 views
0

J'ai créé un simple projet pour tester l'envoi de photo à télégramme bot en php 7, mais rien ne l'envoie après le démarrage du bot, cependant ce projet tourne en PHP 5.3! Y at-il quelque chose de différent dans php 7 que je devrais utiliser?Comment envoyer une photo dans le télégramme bot en php 7.0.2

$message = file_get_contents("php://input"); 
$result = json_decode($message,true); 
$token = "My_Robot_token"; 

if($result['message']['text']=='/start') 
{ 
    $target_url = "https://api.telegram.org/bot".$token."/sendPhoto"; 
    $file_path = "./img/img1.jpg"; 
    $file_name_with_full_path = realpath($file_path); 
    $chat_id = $result['message']['chat']['id']; 
    $photo_send = array(
     'chat_id' => $chat_id, 
     'photo' => '@'.$file_name_with_full_path, 
     'caption' => 'photo sent!' 
    ); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$target_url); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $photo_send); 
    $result=curl_exec ($ch); 
    file_put_contents('res.txt', $ch); 
} 

Répondre

0

Vous devez désactiver le téléchargement sécurisé.

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); 

Ref: curl_setopt