【问题标题】:curl file path must be change when using cron jobs in host?在主机中使用 cron 作业时必须更改 curl 文件路径?
【发布时间】:2023-03-08 11:41:01
【问题描述】:

嗨,我有一个 php 代码,可以使用 bot api 发送电报消息。 现在我有一个问题,使用 curl 来实现文件路径。 问题是:当我重新加载页面以通过 api 发送照片消息时,它可以工作,但是当我在主机中创建新的 cron 作业时,它不会发送照片。 我认为问题出在文件的 curlpath 上

<?php



$boturl='https://api.telegram.org/bot' . $botToken .'/';


$cfile = new CURLFile(realpath("upload2/$file")); //first parameter is YOUR IMAGE path
    $data = [
        'chat_id' => $chat_id , 
        'document' => $cfile,
		'caption' => $matn,
        ];

    $ch = curl_init($boturl.'sendDocument');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $result = curl_exec($ch);
    curl_close($ch);


?>

使用 cron 作业时的问题在哪里? tnx

【问题讨论】:

  • tnx 那是真的老兄:))

标签: php curl cron


【解决方案1】:

使用完整路径而不是相对路径。

例如:

$cfile = new CURLFile(realpath(__DIR__ . "/upload2/$file"));

因为相对路径取决于您执行脚本的位置。

【讨论】:

  • tnx 那是真的,伙计 :))))
猜你喜欢
  • 2011-03-09
  • 2017-06-11
  • 1970-01-01
  • 2012-06-29
  • 2012-09-07
  • 1970-01-01
  • 1970-01-01
  • 2010-09-20
  • 2018-01-03
相关资源
最近更新 更多