Php 媒体上载文件大小():由于上载错误Laravel-TwitterOauth,stat失败
我使用亚伯拉罕的软件包从Laravel应用程序发送推特消息 我还使用Laravel任务调度来调度消息。 我还需要用这个软件包发送媒体推特消息。它工作正常。但它不适用于laravel任务调度控制台命令 我的twitter消息发送代码如下:Php 媒体上载文件大小():由于上载错误Laravel-TwitterOauth,stat失败,php,laravel,twitter-oauth,Php,Laravel,Twitter Oauth,我使用亚伯拉罕的软件包从Laravel应用程序发送推特消息 我还使用Laravel任务调度来调度消息。 我还需要用这个软件包发送媒体推特消息。它工作正常。但它不适用于laravel任务调度控制台命令 我的twitter消息发送代码如下: $screenshot = $this->takeScreenShot(); $media = $this->twitter->upload('media/upload', arr
$screenshot = $this->takeScreenShot();
$media = $this->twitter->upload('media/upload', array('media' => "uploads/$screenshot", 'media_type' => 'image/png'), true);
$parameters = [
'status' => $twitterMsg,
'media_ids' => implode(',', [$media->media_id_string])
];
$result = $this->twitter->post('statuses/update',
$parameters);
它抛出以下错误:
filesize(): stat failed for uploads/screenshots_1620116807.png
at vendor/abraham/twitteroauth/src/TwitterOAuth.php:417
413▕ 'shared',
414▕ ];
415▕ $base = [
416▕ 'command' => 'INIT',
➜ 417▕ 'total_bytes' => filesize($parameters['media']),
418▕ ];
419▕ $allowed_parameters = array_intersect_key(
420▕ $parameters,
421▕ array_flip($allowed_keys),
+3 vendor frames
4 app/Services/TwitterService.php:219
Abraham\TwitterOAuth\TwitterOAuth::upload()
如何解决console任务命令的此错误
谢谢这可能是因为您在
媒体
上以上传/截图_1620116807.png
的形式提供了相对路径。尝试传递到媒体的绝对路径,例如通过存储路径
或公共路径
辅助方法:
$media=$this->twitter->upload('media/upload')[
“媒体”=>公共路径(“上传/$screenshot”),
“媒体类型”=>“图像/png”,
],对);
错误消息很可能意味着它在您给定的路径下找不到文件。任务计划程序中的执行上下文可能与运行创建正常前端输出的脚本时不同,可能具有不同的工作目录。试着给出一个完整的绝对路径。实际上它并没有存储在存储路径中。我以前存储在公共路径中。@t没什么不同,请改用public\u path
。您正在尝试将此更改设置为twitter包。我更新了问题。请看一下。@tcetin更新了我的答案