Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从远程url下载并上载文件,而无需在php中保存到HDD_Php_Curl_File Upload_Telegram Bot - Fatal编程技术网

从远程url下载并上载文件,而无需在php中保存到HDD

从远程url下载并上载文件,而无需在php中保存到HDD,php,curl,file-upload,telegram-bot,Php,Curl,File Upload,Telegram Bot,我在写两个电报机器人,我需要把照片/声音从一个发送到另一个。 如文档中所述,您可以传递url或使用多部分/表单数据发布文件。 现在我可以获得发送到第一个机器人的图像链接,如下所示: api.telegram.org/file/bot<Token>/photos/file_6.jpg 然后我把它贴出来: $url = API-URL. '/SendPhoto'; $postfields= array( 'chat_id' => $ChatID, 'photo'

我在写两个电报机器人,我需要把照片/声音从一个发送到另一个。 如文档中所述,您可以传递url或使用多部分/表单数据发布文件。 现在我可以获得发送到第一个机器人的图像链接,如下所示:

api.telegram.org/file/bot<Token>/photos/file_6.jpg
然后我把它贴出来:

$url = API-URL. '/SendPhoto';
$postfields= array(
    'chat_id' => $ChatID,
    'photo' => new CURLFile(realpath("photos/" . $path)),
);
$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, $postfields);
$log = curl_exec($ch);
它工作正常,但由于从HDD写入/读取,速度较慢。 有没有什么方法可以让我不保存到硬盘就可以在运行中执行此操作? 我试过这些,但没有效果:

        $postfields = array(
        'chat_id' => $ChatID,
        'photo' => file_get_contents(FILE-HOST-URL . "/" . $path)
    );
// then post the above using curl

或者使用cURL下载文件,并将cURL_exec()返回值传递给$postfields中的“photo”

好,您不能根据电报在机器人之间发送任何消息类型


所以你不能从一个电报机器人向另一个电报机器人发送消息

没人知道吗?我不想在机器人之间发送消息。我正在尝试下载该文件并将其发送到另一个bot。这类似于发送新消息。@MajeedAskari这并不重要。如果您想在两个或多个机器人之间发送文件、消息或任何东西,您可以使用CLI机器人库,如中的theleton或中的Madelineproto
        $postfields = array(
        'chat_id' => $ChatID,
        'photo' => file_get_contents(FILE-HOST-URL . "/" . $path)
    );
// then post the above using curl