I'm not using the script for coppermine, but I am using it for another gallery website thing... and I'm trying to figure out why it won't read alternative files with the content type "multipart/related".
<?php
######################################
#Coded By Jijo Last Update Date[Jan/19/06]
#####################################
##########################################################
###################### Class readattachment ###############
class Readattachment
{
var $username;
var $encrypted;
var $pic;
var $time;
var $url;
var $caption;
var $tag;
var $mes;
function Readattachment()
{
$this->CI=& get_instance();
}
function checkExists($username, $password)
{
$query = $this->CI->db->get_where('project_users', array('username' => $username, 'password' => $password));
if ($query->num_rows() > 0)
{
return true;
} else {
return false;
exit;
}
}
function checkAndUpload($arg, $pic)
{
preg_match("#username: ([a-zA-Z0-9]+)#i",$arg,$username);
$username = $username[1];
preg_match("#password: ([a-zA-Z0-9]+)#i",$arg,$password);
$password = $password[1];
preg_match("#caption: ([a-zA-Z0-9]+)#i",$arg,$caption);
$caption = 'Default';
$encrypted = md5($password);
$this->checkExists($username, $encrypted);
$this->uploadData($username, $encrypted, $pic, time(), '', $caption, 'nsfw');
}
function getdecodevalue($message,$coding)
{
if ($coding == 0)
{
$message = imap_8bit($message);
}
elseif ($coding == 1)
{
$message = imap_8bit($message);
}
elseif ($coding == 2)
{
$message = imap_binary($message);
}
elseif ($coding == 3)
{
$message=imap_base64($message);
}
elseif ($coding == 4)
{
$message = imap_qprint($message);
}
elseif ($coding == 5)
{
$message = imap_base64($message);
}
return $message;
}
function getdata($host,$login,$password,$savedirpath)
{
$mbox = imap_open ($host, $login, $password) or die("can't connect: " . imap_last_error());
$message = array();
$message["attachment"]["type"][0] = "text";
$message["attachment"]["type"][1] = "multipart";
$message["attachment"]["type"][2] = "message";
//$message["attachment"]["type"][3] = "application";
//$message["attachment"]["type"][4] = "audio";
$message["attachment"]["type"][5] = "image";
//$message["attachment"]["type"][6] = "video";
$message["attachment"]["type"][7] = "other";
for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++)
{
$headerinfo = imap_header($mbox, $jk);
$subject = $headerinfo->Subject;
$matches = array();
if (preg_match('/^=\?[^?]*\?B\?(.*)\?=/m', $subject, $matches))
$subject = base64_decode($matches[1]);
$structure = imap_fetchstructure($mbox, $jk , FT_UID);
$parts = $structure->parts;
$fpos=1;
for($i = 0; $i < count($parts); $i++)
{
$message["pid"][$i] = ($i);
$part = $parts[$i];
if ($part->type == 0) {
$fpos+=1;
continue;
}
if(TRUE)
{
$message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
$message["subtype"][$i] = strtolower($part->subtype);
$ext=$part->subtype;
if ($part->ifdparameters)
foreach($part->dparameters as $dparam)
if (strtolower($dparam->attribute) == 'filename') $filename = $dparam->value;
if (empty($filename))
if ($part->ifparameters)
foreach($part->parameters as $param)
if (strtolower($param->attribute) == 'name') $filename = $param->value;
if (empty($filename) && $part->ifid)
$filename = trim($part->id, '<>');
if (empty($filename)) $filename = 'nfn' . rand() . '.' . strtolower($part->subtype);
$mege="";
$data="";
$mege = imap_fetchbody($mbox,$jk,$fpos);
$body = imap_body($mbox, $jk);
$fp=fopen($savedirpath . $filename,w);
$data=$this->getdecodevalue($mege,$part->type);
fputs($fp,$data);
fclose($fp);
$this->checkAndUpload($body, $filename);
$fpos+=1;
}
}
imap_delete($mbox,$jk);
}
imap_expunge($mbox);
imap_close($mbox);
}
function uploadData($username, $encrypted, $pic, $time, $url, $caption, $tag)
{
$this->CI->db->insert('pb_photos', array('time' => time(), 'pic' => $pic, 'url' => base_url() . 'system/application/views/uploads/', 'caption' => $caption, 'poster' => $username, 'tag' => $tag));
}
}
?>
I commented out a couple attachment types because I only want images to be uploaded. If you see any easy solution to this, please let me know. It downloads the attachment from the multipart/related, but saves as something like nfn242525.alternative. So the folder path isn't what's wrong here... it's the saving part that is wrong.