Размер файла: 2.2Kb
<?php
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
ini_set ('max_execution_time', "0");
// Параметры POP3
// сервер
$pop3host='mail.znwap.ru';
// логин
$pop3login='[email protected]';
// пароль
$pop3pass='test';
include("config.php");
include('functions.php');
include('POP3.php');
$lnk = mysql_connect($hostname,$username,$password);
mysql_select_db($dbname, $lnk);
mysql_query("SET NAMES utf8");
$pop3=new Net_POP3();
$pop3->connect($pop3host, 110);
$pop3->login($pop3login, $pop3pass,'USER');
$inf="\n[".date("d.m.Y H:i:s")."]\n";
$num=$pop3->numMsg();
if (!$num) $inf.="no mes\n";
for ($n=1; $n<=$num; $n++) {
$h=$pop3->getParsedHeaders($n);
$to=$h['To'];
if (!preg_match('|(\d+)(\d{4})\@|i', $to, $m)) {$inf.="bad to $to mes $n\n";continue;}
$res=mysql_query("SELECT * FROM zn_anket WHERE id='$m[1]' AND loadcode='$m[2]'");
if (!mysql_num_rows($res)) {$inf.="bad user $to mes $n\n";continue;}
$u=mysql_fetch_array($res);
$b=$pop3->getBody($n);
$s=1;
//echo "<pre>" . htmlspecialchars($pop3->getMsg($n)) . "</pre>\n";
preg_match('|boundary\s*\=\s*\"?([^\"]+)\"?|', $h['Content-Type'], $ma);
$boundary=trim($ma[1]);
//echo "<pre>\nboundary:$boundary\n</pre>";
while ($p=stripos($b, 'Content-Type: image/', $s)) {
//echo "OK";
$me="";
while (!strstr($me, "\r\n\r\n")) {
$me.=$b{$p};
$p++;
}
$data="";
while (!strstr($data, $boundary)) {
$data.=$b{$p};
$p++;
}
$data=trim(str_replace($boundary, "", $data));
//echo "<pre>$inf\n\n$data</pre>";
$s=$p;
$fid=$u['id'].'_'.($u['photo']+1);
$act='jpg';
//echo "images/$fid.$act";
$fp=fopen("images/$fid.$act", "w");
fwrite($fp, base64_decode($data));
fclose($fp);
@chmod("images/$fid.$act", 0777);
@resizeimage("images/$fid.$act", $max_width, $max_height);
if (!@getimagesize("images/$fid.$act")) {
$inf.="bad image $fid.$act";
unlink("images/$fid.$act");
} else {
$inf.="ok $fid.$act\n";
$u['photo']++;
mysql_query("UPDATE zn_anket SET photo='$u[photo]' WHERE id='$u[id]'");
}
}
}
for ($n=1; $n<=$num; $n++) {
$pop3->deleteMsg($n);
}
$pop3->disconnect();
$fp=fopen('loadlog.txt', 'a+');
fwrite($fp, $inf);
fclose($fp);
echo "<pre>".htmlspecialchars($inf)."</pre>";
?>