I'm programming a telegram bot. I want to send an image to a series of IDs that are stored in my DB (I'M NOT UPLOADING A PHOTO I'M JUST SENDING IT). The function to send the image works just fine. The only problem I have is that images that are above 1MB size won't be sended.

I don't upload these images anywhere, I just send them specifying the image url (so it isn't a problem about a max size upload).

/*this is the function that I use to send the image*/


include "./db.php";
include "../Gestionale-Bar/webhook.php";

$queryID="SELECT DISTINCT acquirente FROM BackupChat ORDER BY acquirente";
$file =new CURLFile(realpath($_FILES["photo"]["tmp_name"]));
while($rowID = $resultID->fetch_assoc())
  $url        = $website . "/sendPhoto?chat_id=" . $rowID['acquirente'] ;
  $post_fields = array('chat_id'   => $rowID['acquirente'], 'photo'     => $file);

  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  curl_setopt($ch, CURLOPT_URL, $url); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
  $output = curl_exec($ch);

echo "<script language=\"Javascript\">

/*this is the input button where I select the photo*/

function img()
  var gridWrapper = document.querySelector('.content');
  gridWrapper.innerHTML =
    "<form action=\"inviaimg.php\" enctype=\"multipart/form-data\" method=\"post\" class=\"inputfile\">" +
    "<input type=\"file\" name=\"photo\"/>" +
    "<input type=\"submit\" value=\"send\" style=\"background-color:#2a2b30; color:#5c5edc; font-family:AvenirNext; width:10%; height:30px\"></form>"

Whenever I try to send an image that is under 1MB everything works fine. So basically I expect to send photos with bigger size. :)

1 Answers

Kacper Pruszyński On

in your $post_fields you have key photo which value is CURLFile object. In documentation of telegram bots it is written that it belongs pass a value which is file_id as String to send a photo that exists on the Telegram servers, HTTP URL as a String for Telegram to get a photo from the Internet or upload a local photo by passing a file path.

You wrote you didn't upload a file but just sending. Despite this you use a $_FILES[] to get a realpath() of file which is uploaded. Maybe this is a fault of upload_max_filesize. Checkout this.

Check also this this piece of code:

$file = realpath($_FILES["photo"]["tmp_name"]);
while($rowID = $resultID->fetch_assoc())
   $url        = $website . "/sendPhoto?chat_id=" . $rowID['acquirente'] ;
   $post_fields = array('chat_id'   => $rowID['acquirente'], 'photo'     => $file

Replace old one with this and give feedback. Greetings, plum!