我想将媒体/图片消息从https://github.com/venomous0x/WhatsAPI保存到AWS S3。我尝试了这段代码,它可以在本地获取图片并且没有错误,但是它没有保存到AWS S3。
require_once 'S3.php';
require_once 'src/whatsprot.class.php';
$username = 'username';
$password = 'password';
$nickname = 'nickname';
$bucket = 'mybucket';
$accesskey = 'accesskey';
$secretkey = 'secretkey';
$fileName = $_FILES['pictures/']['name'];
$fileTempName = $_FILES['pictures/']['tmp_name'];
$options = array('params' => array('ACL' => 'public-read', 'ContentType' => 'image/jpeg'));
$s3 = new S3($accesskey, $secretkey);
function onGetImage($mynumber, $from, $id, $type, $t, $name, $size, $url, $file, $mimetype, $filehash, $width, $height, $preview){
$data = file_get_contents($url);
$fulluri = "pictures/" . $file;
$fp = @fopen($fulluri, "w");
if ($fp) {
fwrite($fp, $data);
fclose($fp);
}
S3::putObject(S3::inputFile($file), $bucket, $uri, $options);
}
$w = new WhatsProt($username, 0, $nickname, true);
$w->eventManager()->bind("onGetImage", "onGetImage");
$w->connect();
$w->loginWithPassword($password);
$w->pollMessage($autoReceipt = true);
$messages = $w->getMessages();
请指导我。非常感谢。