Ik heb een script dat de jpg uit een mail haalt en die in een folder van de website zet.
Echter...
Als de jpg van een mms afkomstig is dan doet ie er niets meer mee.
Het schijnt dat de MIME van een mms jpg anders is dan van een normale jpg.
OCTET-STREAM schijnt de MIME van een mms jpg te zijn.
Kan ik het script zo aanpassen dat hij ook OCTET-STREAM aankan?
Zo ja...hoe?
Hier het script:
<?
include_once("config.php");
$photow = '640 px';
$photoh = '480 px';
$domain = 'http://www.derodehaan.nl';
$mail_user_id = 'mms@derodehaan.nl';
$mail_password = "********";
$iso = 'Y-m-d H:i:s';
if($mbox = imap_open("{imap.derodehaan.nl:143/imap/notls}INBOX",$mail_user_id,$mail_password))
{
$mtnum = imap_num_msg($mbox);
if($mtnum > 0){
for($mnum = 1;$mnum <= $mtnum; $mnum++){
$mcontent = imap_fetchbody($mbox,$mnum,1);
$mheader = imap_headerinfo($mbox,$mnum);
$mheader->fromaddress = preg_replace("/<(.*?)>/si", "", $mheader->fromaddress);
$mstructure = imap_fetchstructure($mbox,$mnum);
if($mstructure->subtype == 'MIXED')
{
for($mpart = 1;!empty($mstructure->parts[$mpart]->dparameters[0]->value);$mpart++){
$mdata = imap_fetchbody($mbox,$mnum,$mpart + 1);
$mdecode = base64_decode($mdata);
$mimage = imagecreatefromstring($mdecode);
$mfilename = $mstructure->parts[$mpart]->dparameters[0]->value;
$mwidth = imagesx($mimage);
$mheigth = imagesy($mimage);
if($photow < $mwidth){
$mprop = $photow / $mwidth;
$mnewwidth = $photow;
$mnewheight = $mheigth * $mprop;
$mnewheight = round($mnewheight);
$mnewimage = imagecreatetruecolor($mnewwidth, $mnewheight);
imagecopyresampled($mnewimage, $mimage, 0, 0, 0, 0, $mnewwidth, $mnewheight, $mwidth, $mheigth);
if(file_exists('images/upload/2006/'.$mfilename)){
unlink('images/upload/2006/'.$mfilename);
}
// if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
// imagejpeg($mnewimage,'images/upload/'.$mfilename);
// }else{
// imagepng($mnewimage,'images/upload/'.$mfilename);
// }
$fileContruct = explode(".",$mstructure->parts[$mpart]->dparameters[0]->value);
$count = sizeof($fileContruct)-1;
$fileExtension = $fileContruct[$count];
$fileExtension."<br>\n";
switch($fileExtension) {
case "jpeg":
case "jpg":
imagejpeg($mnewimage,'images/upload/2006/'.$mfilename);
break;
case "png":
imagepng($mnewimage,'images/upload/2006/'.$mfilename);
break;
}
}
else {
if(file_exists('images/upload/2006/'.$mfilename)){
unlink('images/upload/2006/'.$mfilename);
}
// if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
// imagejpeg($mimage,'images/upload/'.$mfilename);
// }
// else{
// imagepng($mimage,'images/upload/'.$mfilename);
// }
$fileContruct = explode(".",$mstructure->parts[$mpart]->dparameters[0]->value) ;
$count = sizeof($fileContruct) ;
$fileExtension = $fileContruct[$count];
$fileExtension."<br>\n";
switch($fileExtension) {
case "jpeg":
case "jpg":
imagejpeg($mnewimage,'images/upload/2006/'.$mfilename);
break;
case "png":
imagepng($mnewimage,'images/upload/2006/'.$mfilename);
break;
}
}
$mcontent.='[*img]'.$domain.'images/upload/2006/'.$mfilename.'[/img]\n';
imagedestroy($mimage);
}
}
$mcontent = mysql_real_escape_string($mcontent);
$mheader->fromaddress = mysql_real_escape_string($mheader->fromaddress);
$mheader->date = mysql_real_escape_string($mheader->date);
$iso = mysql_real_escape_string($iso);
$sql = "INSERT INTO `".$prefix."weblog` (`subject`,`date`,`content`,`author`) VALUES ('".$mheader->subject."','".date($iso, strtotime($mheader->date))."','".($mcontent)."','".$mheader->fromaddress."')";$sql = "INSERT INTO `".$prefix."weblog` (`subject`,`date`,`content`,`author`) VALUES ('".$mheader->subject."','".date($iso, strtotime($mheader->date))."','".($mcontent)."','".$mheader->fromaddress."')";
$update = mysql_query($sql) or die(mysql_error());
imap_delete($mbox,$mnum);
}
}
imap_expunge($mbox);
imap_close($mbox);
}
else{
echo 'Geen verbinding mogelijk';
}
?>
Echter...
Als de jpg van een mms afkomstig is dan doet ie er niets meer mee.
Het schijnt dat de MIME van een mms jpg anders is dan van een normale jpg.
OCTET-STREAM schijnt de MIME van een mms jpg te zijn.
Kan ik het script zo aanpassen dat hij ook OCTET-STREAM aankan?
Zo ja...hoe?
Hier het script:
<?
include_once("config.php");
$photow = '640 px';
$photoh = '480 px';
$domain = 'http://www.derodehaan.nl';
$mail_user_id = 'mms@derodehaan.nl';
$mail_password = "********";
$iso = 'Y-m-d H:i:s';
if($mbox = imap_open("{imap.derodehaan.nl:143/imap/notls}INBOX",$mail_user_id,$mail_password))
{
$mtnum = imap_num_msg($mbox);
if($mtnum > 0){
for($mnum = 1;$mnum <= $mtnum; $mnum++){
$mcontent = imap_fetchbody($mbox,$mnum,1);
$mheader = imap_headerinfo($mbox,$mnum);
$mheader->fromaddress = preg_replace("/<(.*?)>/si", "", $mheader->fromaddress);
$mstructure = imap_fetchstructure($mbox,$mnum);
if($mstructure->subtype == 'MIXED')
{
for($mpart = 1;!empty($mstructure->parts[$mpart]->dparameters[0]->value);$mpart++){
$mdata = imap_fetchbody($mbox,$mnum,$mpart + 1);
$mdecode = base64_decode($mdata);
$mimage = imagecreatefromstring($mdecode);
$mfilename = $mstructure->parts[$mpart]->dparameters[0]->value;
$mwidth = imagesx($mimage);
$mheigth = imagesy($mimage);
if($photow < $mwidth){
$mprop = $photow / $mwidth;
$mnewwidth = $photow;
$mnewheight = $mheigth * $mprop;
$mnewheight = round($mnewheight);
$mnewimage = imagecreatetruecolor($mnewwidth, $mnewheight);
imagecopyresampled($mnewimage, $mimage, 0, 0, 0, 0, $mnewwidth, $mnewheight, $mwidth, $mheigth);
if(file_exists('images/upload/2006/'.$mfilename)){
unlink('images/upload/2006/'.$mfilename);
}
// if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
// imagejpeg($mnewimage,'images/upload/'.$mfilename);
// }else{
// imagepng($mnewimage,'images/upload/'.$mfilename);
// }
$fileContruct = explode(".",$mstructure->parts[$mpart]->dparameters[0]->value);
$count = sizeof($fileContruct)-1;
$fileExtension = $fileContruct[$count];
$fileExtension."<br>\n";
switch($fileExtension) {
case "jpeg":
case "jpg":
imagejpeg($mnewimage,'images/upload/2006/'.$mfilename);
break;
case "png":
imagepng($mnewimage,'images/upload/2006/'.$mfilename);
break;
}
}
else {
if(file_exists('images/upload/2006/'.$mfilename)){
unlink('images/upload/2006/'.$mfilename);
}
// if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
// imagejpeg($mimage,'images/upload/'.$mfilename);
// }
// else{
// imagepng($mimage,'images/upload/'.$mfilename);
// }
$fileContruct = explode(".",$mstructure->parts[$mpart]->dparameters[0]->value) ;
$count = sizeof($fileContruct) ;
$fileExtension = $fileContruct[$count];
$fileExtension."<br>\n";
switch($fileExtension) {
case "jpeg":
case "jpg":
imagejpeg($mnewimage,'images/upload/2006/'.$mfilename);
break;
case "png":
imagepng($mnewimage,'images/upload/2006/'.$mfilename);
break;
}
}
$mcontent.='[*img]'.$domain.'images/upload/2006/'.$mfilename.'[/img]\n';
imagedestroy($mimage);
}
}
$mcontent = mysql_real_escape_string($mcontent);
$mheader->fromaddress = mysql_real_escape_string($mheader->fromaddress);
$mheader->date = mysql_real_escape_string($mheader->date);
$iso = mysql_real_escape_string($iso);
$sql = "INSERT INTO `".$prefix."weblog` (`subject`,`date`,`content`,`author`) VALUES ('".$mheader->subject."','".date($iso, strtotime($mheader->date))."','".($mcontent)."','".$mheader->fromaddress."')";$sql = "INSERT INTO `".$prefix."weblog` (`subject`,`date`,`content`,`author`) VALUES ('".$mheader->subject."','".date($iso, strtotime($mheader->date))."','".($mcontent)."','".$mheader->fromaddress."')";
$update = mysql_query($sql) or die(mysql_error());
imap_delete($mbox,$mnum);
}
}
imap_expunge($mbox);
imap_close($mbox);
}
else{
echo 'Geen verbinding mogelijk';
}
?>