0

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*/


<?php

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

$queryID="SELECT DISTINCT acquirente FROM BackupChat ORDER BY acquirente";
$resultID=$conn->query($queryID);
$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(
    "Content-Type:multipart/form-data"
  ));
  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\">
window.location.href='mywebpageblablabla';
</script>
";

?>
/*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. :)

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Synapsis
  • 667
  • 1
  • 5
  • 19
  • Possible duplicate of [Change the maximum upload file size](https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size) – miken32 Apr 21 '19 at 21:26

1 Answers1

0

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!

Sources:

plumthedev
  • 70
  • 12
  • Hi, and thanks for your reply. Unluckly this didn't fix the issue... actually, switching to this code didn't even allow me to send images anymore. Thanks anyway :) – Synapsis Apr 22 '19 at 00:13