我需要使用“input type =”file“”发送图像,对图像大小没有任何限制

问题描述 投票:0回答:1

我正在编程一个电报机器人。我想将图像发送到存储在我的数据库中的一系列ID(我不会上传照片我只是发送它)。发送图像的功能很好。我唯一的问题是不会发出超过1MB大小的图像。

我没有在任何地方上传这些图片,我只是发送它们指定图片网址(所以这不是最大尺寸上传的问题)。

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

每当我尝试发送1MB以下的图像时,一切正常。所以基本上我希望发送更大尺寸的照片。 :)

php html file-upload bots telegram
1个回答
0
投票

在你的$ post_fields中你有关键照片,其值是CURLFile对象。在电报机器人的文档中,写入它所属的传递值为file_id为String以发送存在于Telegram服务器上的照片,HTTP URL作为Telegram的字符串以从Internet获取照片或上传本地照片传递文件路径。

您写道,您没有上传文件,只是发送。尽管如此,你还是使用$ _FILES []来获取上传文件的realpath()。也许这是upload_max_filesize的错误。结帐这个。

检查这段代码:

$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
);

用这个替换旧的并给出反馈。问候,梅花!

资料来源:

© www.soinside.com 2019 - 2024. All rights reserved.