Просмотр файла script/admin/email_upload.php

Размер файла: 3.71Kb
<?php
/*-----------------------------------------------------------------------------------------
mcGalleryPRO
All code is © 2003 Marc Cagninacci.
No files may be redistributed in whole or significant part.
----------------- mcgalleryPRO IS NOT FREE SOFTWARE -------------------
You should have receive a file called license.txt in this package
--------------------------------------------------------------------------------------------*/

include 'conf.inc.php';

$pop_account = '{'.$pop_server.':110/pop3}INBOX';

$mbox = imap_open ($pop_account , $pop_login, $pop_pass);
$check = imap_check($mbox);
$nbmes = $check -> Nmsgs;
if ($nbmes > 0)
{
$nm = 1;
	while ($nm <= $nbmes)
	{
	$o = imap_fetchstructure($mbox, $nm);
		if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED'))
		{
		$headers = imap_header($mbox, $nm);
		$subject = $headers->Subject;
		list($log, $passw, $title, $dir) = split('/', $subject);
			if ($log == $admin_login && $passw == $admin_pass)
			{
			$connection = mysql_connect($host,$login,$pass);
			mysql_select_db($base, $connection);

			$query= "SELECT album, cat FROM mcgallery_photo WHERE idalbum=$dir";
			$res = mysql_query($query);
			$isdir = mysql_num_rows($res);
			$row = mysql_fetch_array($res);
				if ($isdir > 0)
				{
				$parts = $o->parts;
				$i=1;
					foreach($parts as $part)
					{
					$filename = '';
					if (isset($part->encoding) && $part->encoding == 3)
						$str = imap_base64(imap_fetchbody($mbox, $nm, $i));
					else
						$str = imap_fetchbody($mbox, $nm, $i);
						if ($part->ifdparameters == 1)
						{
						$dparams = $part->dparameters;
							foreach($dparams as $dparam)
							{
							if ($dparam->attribute == 'FILENAME') $filename = $dparam->value;
							}
						}
						if ($filename == '')
						{
							if ($part->ifparameters == 1)
							{
							$params = $part->parameters;
								foreach($params as $param)
								{
									if ($param->attribute == 'NAME')  $filename = $param->value;
								}
							}
						}
						if (ereg('.jpg', $filename))
						{
						$text=imap_fetchbody($mbox,$nm,"1.1");

						$filename = date("mdhis").'.jpg';
						$fp = fopen('../photos/'.$dir.'/'.$filename, "w");
							if (!$fp)  return FALSE;
						fwrite($fp, $str);
						fclose($fp);
						chmod('../photos/'.$dir.'/'.$filename, 0777 );

						$image = ImageCreateFromJPEG('../photos/'.$dir.'/'.$filename);
						$width = imagesx($image) ;
						$height = imagesy($image) ;
						$new_width = $thumb_width;
						$new_height = ($new_width * $height) / $width ;
							if ($gd_ver == 1)
							{
							$thumb = imagecreate($new_width,$new_height);
							imagecopyresized($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height);
							}
							elseif ($gd_ver == 2)
							{
							$thumb = imagecreatetruecolor($new_width,$new_height);
							imagecopyresampled($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height);
							}
						ImageJPEG($thumb, '../photos/'.$dir.'/small/'.$filename);
						chmod('../photos/'.$dir.'/small/'.$filename, 0777 );

						$file = $dir.'_'.$filename;

						$album = addslashes($row['album']);
						$cat = addslashes($row['cat']);
						$title = addslashes($title);
						$text = addslashes($text);
						$date = date("Y-m-d");
						$query = "INSERT INTO mcgallery_photo (file, idalbum, album, cat, title, descr, add_date) VALUES ('$file', '$dir', '$album', '$cat', '$title', '$text', '$date')";
						mysql_query($query);
						mysql_close();
						}
					$i++;
					}
				}
			echo $dir.' / '.$filename.':  '.$title.' - '.$text.'<br><br>';
			}
		}
	imap_delete ($mbox, $nm);
	$nm++;
	}
}
imap_expunge ($mbox);
imap_close ($mbox);
?>