Need a script to upload image files via email in php
Email upload
Collapse
X
-
Here is a code but you need to edit it.
PHP Code:<?php
if ($mbox=imap_open("{mail.domain.com:143/imap/notls}INBOX","email@domain.com","pass"))
{
$num = imap_num_msg($mbox);
for( $i=1; $i<=$num; $i++ )
{
$header = imap_fetchheader( $mbox, $i, FT_PREFETCHTEXT);
$header2 = imap_fetch_overview( $mbox, $i);
$param=get_object_vars($header2[0]);
$struct=imap_fetchstructure( $mbox, $i);
$struct=get_object_vars($struct);
$subj=$param['subject'];
$subj=imap_mime_header_decode($subj);
$subj=get_object_vars($subj[0]);
$subj=$subj['text'];
$parameter=$struct['parameters'];
$parts=$struct['parts'];
$count_parts=sizeof($struct['parts']);
if ($count_parts<=1)
{
$count_parts=1;
$encoding[0]=$struct['encoding'];
$subtype[0]=$struct['subtype'];
$type[0]=$struct['type'];
$i_param_found=false;
if ($part['ifparameters'])
{
$parameter_a=$part['parameters'];
for ($i_param=0;(($i_param<sizeof($parameter_a)) && !$i_param_found);$i_param++)
{
$parameter=get_object_vars($parameter_a[$i_param]);
$atrib[$j-1]=$parameter['attribute'];
$value[$j-1]=$parameter['value'];
if (($atrib[$j-1]=='NAME')||($atrib[$j-1]=='FILENAME')) $i_param_found=true;
}
}
if ($part['ifdparameters'] && !$i_param_found)
{
$parameter_a=$part['dparameters'];
for ($i_param=0;(($i_param<sizeof($parameter_a)) && !$i_param_found);$i_param++)
{
$parameter=get_object_vars($parameter_a[$i_param]);
$atrib[$j-1]=$parameter['attribute'];
$value[$j-1]=$parameter['value'];
if (($atrib[$j-1]=='NAME')||($atrib[$j-1]=='FILENAME')) $i_param_found=true;
}
}
}
if ($count_parts>1)
{
for ($j=1;$j<=$count_parts;$j++)
{
$part=get_object_vars($parts[$j-1]);
$encoding[$j-1]=$part['encoding'];
$subtype[$j-1]=$part['subtype'];
$type[$j-1]=$part['type'];
$i_param_found=false;
if ($part['ifparameters'])
{
$parameter_a=$part['parameters'];
for ($i_param=0;(($i_param<sizeof($parameter_a)) && !$i_param_found);$i_param++)
{
$parameter=get_object_vars($parameter_a[$i_param]);
$atrib[$j-1]=$parameter['attribute'];
$value[$j-1]=$parameter['value'];
if (($atrib[$j-1]=='NAME')||($atrib[$j-1]=='FILENAME')) $i_param_found=true;
}
}
if ($part['ifdparameters'] && !$i_param_found)
{
$parameter_a=$part['dparameters'];
for ($i_param=0;(($i_param<sizeof($parameter_a)) && !$i_param_found);$i_param++)
{
$parameter=get_object_vars($parameter_a[$i_param]);
$atrib[$j-1]=$parameter['attribute'];
$value[$j-1]=$parameter['value'];
if (($atrib[$j-1]=='NAME')||($atrib[$j-1]=='FILENAME')) $i_param_found=true;
}
}
$bp=imap_fetchbody( $mbox, $i, $j, FT_PEEK);
$body[$j-1]=$bp;
}
}
unset($files);
$text='-'.$subj;
for ($j=0;$j<$count_parts;$j++)
{
if ($type[$j]==6) $type[$j]='VIDEO';
elseif ($type[$j]==5) $type[$j]='IMAGE';
elseif ($type[$j]==4) $type[$j]='AUDIO';
elseif ($type[$j]==0) $type[$j]='TEXT';
else $type[$j]='#'.$type[$j];
if (($type[$j]==0)&&(($subtype[$j]=='PLAIN')||($subtype[$j]=='HTML')))
{
$text.=$body[$j];
if ($encoding[$j]==3) $text.=base64_decode($body[$j]);
}
else
{
if (($atrib[$j]=='NAME')||($atrib[$j]=='FILENAME'))
{
$fname=explode('.',strtolower($value[$j]));
$name=$fname[0];
$ext=$fname[1];
$chekname=(strlen(trim(strtr(str_replace(' ','*',$name),'-_()0123456789abcdefghjiklmnopqrstuvwxyz',' ')))==0);
if ($chekname)
if (($ext=='jpg')||
($ext=='jpeg')||
#($ext=='mid')||
#($ext=='3gp')||
#($ext=='mmf')||
($ext=='gif')||
#($ext=='mp3')||
#($ext=='wav')||
($ext=='png')||
#($ext=='jar')||
#($ext=='jad')||
#($ext=='thm')||
#($ext=='mpn')||
#($ext=='amr')||
#($ext=='sis')||
#($ext=='scs')||
#($ext=='col')||
($ext=='wbmp'))
{
if ($encoding[$j]==3)
{
$_file['name']=$name.'.'.$ext;
$_file['body']=base64_decode($body[$j]);
$_file['size']=strlen($_file['body']);
if ($_file['size']<=262144) $files[]=$_file;
}
}
}
}
}
if (strpos($text,'(key:'))
{
$code1=explode('(key:',$text);
$code2=explode(')',$code1[1]);
$_key=$code2[0];
$q=@mysql_query("SELECT * FROM `users` WHERE `upload_key` = '".addslashes($_key)."' LIMIT 1");
$data=@mysql_fetch_array($q);
$_user=$data['username'];
if ($_user!='')
{
$limit=128999999999999900; // limit space
for ($fi=0;$fi<sizeof($files);$fi++)
{
if ($files[$fi]['size']<=$limit)
{
$superdat_name=$_user."_".time().$files[$fi]['name'];
$fp = @fopen ('/path/public_html/folder/'.$superdat_name, "w+");
@fwrite ($fp, $files[$fi]['body']);
@fclose ($fp);
$fsize=round($files[$fi]['size']/1024,1);
}
}
}
}
imap_delete( $mbox, $i );
}
imap_expunge($mbox);
imap_close($mbox);
print_r(imap_errors());
}
exit;
}
?>Attached Files
Comment
Comment