piwigo 自动同步相册
下面代码保存位xx.php,然后
sudo -u root crontab -e
增加到执行任务中,代码执行后会返回一个网页信息,保存到文件中查看,可以看到错误信息和同步的相册。
10 1 * * * php -f /.../sync_pic.php > /.../sync_pic.html
需注意由于piwigo文件权限是root,使用Apache账户会权限失败,查看cron的日志可以确认。
另外这个相册同步后增加的照片会出现未计算校验码的情况还需要自动计算。
https://post.smzdm.com/p/aekeg5lk/
https://piwigo.org/forum/viewtopic.php?id=15529
$baseurl = 'http://yourpiwigo.com';
$username = 'adminuser';
$password = 'adminpassword';
$url = $baseurl.'/identification.php';
$fields = array(
'username' => $username,
'password' => $password,
'redirect' => '',
'login' => 'on'
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$cookieJar = 'synchroCookie';
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookieJar);
curl_exec($ch);
curl_close ($ch);
unset($ch);
$url = $baseurl.'/admin.php?page=site_update&site=1';
$fields = array(
'sync' => urlencode('files'),
'privacy_level' => urlencode('0'),
'subcats-included' => urlencode('1'),
'submit' => urlencode('on')
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookieJar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec($ch);
curl_close ($ch);
unset($ch);
?>