extract image + schrijven naar dir
Het doet niet helemaal wat ik wil, helaas weet de maker/verzender ook niet wat te doen.
Het gaat om een script wat een email opent en een foto eruit haalt en dit een andere naam geeft om het dan te plaatsen in een bepaalde map.
Het openen van de mail gaat prima, ook het verwijderen ervan maar daar tussenin gaat het fout. Ik kan de foto nergens meer terug vinden.
Nu weet ik dat de maker het script via een database plaatst op internet. Voor mijn toepassing is het voldoende als het in een bepaalde map komt te staan.
Wie o wie kan me helpen dit op te lossen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$imapaddress = "{imap.gmail.com:993/imap/ssl}";
$imapmainbox = "INBOX";
$maxmessagecount = 10;
$imapuser = "[email protected]";
$imappassword = "bladiebla";
$timestamp = time();
$timestampCounter = 0;
//paden waar je het op wilt gaan slaan
$imageFileOriginal = "/home/vhosts/bla.nl/httpdocs/php/";
$imageFileThumb = "/home/vhosts/bla.nl/httpdocs/php/";
$imageFileSmall = "/home/vhosts/bla.nl/httpdocs/php/";
$imapaddressandbox = $imapaddress . $imapmainbox;
$mbox = imap_open($imapaddressandbox, $imapuser, $imappassword)
or die("Can't connect to '" . $imapaddress .
"' as user '" . $imapuser .
"' with password '" . $imappassword .
"': " . imap_last_error());
//echo "<u><h1>Gmail information for " . $imapuser ."</h1></u>";
//echo "<h2>Inbox headers</h2>\n";
$headers = imap_headers($mbox)
or die("Geen email: " . imap_last_error());
$totalmessagecount = sizeof($headers);
echo $totalmessagecount . " messages<br/><br/>";
if ($totalmessagecount<$maxmessagecount)
$displaycount = $totalmessagecount;
else
$displaycount = $maxmessagecount;
for ($count=1; $count<=$displaycount; $count+=1) {
$headerinfo = imap_headerinfo($mbox, $count)
or die("Couldn't get header for message " . $count . " : " . imap_last_error());
$from = $headerinfo->fromaddress;
if(isset($headerinfo->subject))
$subject = $headerinfo->subject;
else
$subject = $headerinfo->subject;
$email = $headerinfo->from[0]->mailbox ."@".$headerinfo->from[0]->host;
$date = $headerinfo->date;
echo "<em><u>".$from." - ".$email."</em></u>: ".$subject." - <i>".$date."</i><br />\n";
$struct = imap_fetchstructure($mbox,$count);
$contentParts = count($struct->parts);
for ($i=1;$i<=$contentParts;$i++) {
unset($fields);
$objTmp = imap_bodystruct($mbox,$count,$i);
if($objTmp->subtype=="PLAIN") {
//echo "PLAIN<pre>";
//print_r(imap_bodystruct($mbox,$count,$i));
//echo "</pre>";
}
elseif($objTmp->subtype=="HTML") {
//echo "HTML<pre>";
//echo imap_fetchbody($mbox,$count,1);
//echo "</pre>";
}
elseif($objTmp->subtype=="JPEG") {
echo $imageName = "iphone-".$timestamp.$timestampCounter.".jpg";
$strFileName = $objTmp->parameters[0]->value;
$strFileType = strrev(substr(strrev($strFileName),0,4));
$fileContent = imap_fetchbody($mbox,$count,2);
$fp = fopen($imageFileOriginal.$imageName, "wb");
$timestampCounter++;
fwrite($fp, imap_base64($fileContent));
fclose($fp);
makeSquareThumbIM($imageName, $imageFileOriginal, $imageFileThumb, '100');
makeMaximumThumbIM($imageName, $imageFileOriginal, $imageFileSmall, '620');
$fields['crDate'] = $timestamp;
$fields['image'] = $imageName;
$fields['email'] = $email;
$fields['description'] = $subject;
echo "<pre>";
print_r($fields);
echo "</pre>";
$db->changeTable($fields, '', TBL_IPHONE);
}
}
//mail markeren voor verwijdering
imap_delete($mbox, $count);
}
//verwijder alle gemarkeerde emails.
imap_expunge($mbox);
imap_close($mbox);
?>
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$imapaddress = "{imap.gmail.com:993/imap/ssl}";
$imapmainbox = "INBOX";
$maxmessagecount = 10;
$imapuser = "[email protected]";
$imappassword = "bladiebla";
$timestamp = time();
$timestampCounter = 0;
//paden waar je het op wilt gaan slaan
$imageFileOriginal = "/home/vhosts/bla.nl/httpdocs/php/";
$imageFileThumb = "/home/vhosts/bla.nl/httpdocs/php/";
$imageFileSmall = "/home/vhosts/bla.nl/httpdocs/php/";
$imapaddressandbox = $imapaddress . $imapmainbox;
$mbox = imap_open($imapaddressandbox, $imapuser, $imappassword)
or die("Can't connect to '" . $imapaddress .
"' as user '" . $imapuser .
"' with password '" . $imappassword .
"': " . imap_last_error());
//echo "<u><h1>Gmail information for " . $imapuser ."</h1></u>";
//echo "<h2>Inbox headers</h2>\n";
$headers = imap_headers($mbox)
or die("Geen email: " . imap_last_error());
$totalmessagecount = sizeof($headers);
echo $totalmessagecount . " messages<br/><br/>";
if ($totalmessagecount<$maxmessagecount)
$displaycount = $totalmessagecount;
else
$displaycount = $maxmessagecount;
for ($count=1; $count<=$displaycount; $count+=1) {
$headerinfo = imap_headerinfo($mbox, $count)
or die("Couldn't get header for message " . $count . " : " . imap_last_error());
$from = $headerinfo->fromaddress;
if(isset($headerinfo->subject))
$subject = $headerinfo->subject;
else
$subject = $headerinfo->subject;
$email = $headerinfo->from[0]->mailbox ."@".$headerinfo->from[0]->host;
$date = $headerinfo->date;
echo "<em><u>".$from." - ".$email."</em></u>: ".$subject." - <i>".$date."</i><br />\n";
$struct = imap_fetchstructure($mbox,$count);
$contentParts = count($struct->parts);
for ($i=1;$i<=$contentParts;$i++) {
unset($fields);
$objTmp = imap_bodystruct($mbox,$count,$i);
if($objTmp->subtype=="PLAIN") {
//echo "PLAIN<pre>";
//print_r(imap_bodystruct($mbox,$count,$i));
//echo "</pre>";
}
elseif($objTmp->subtype=="HTML") {
//echo "HTML<pre>";
//echo imap_fetchbody($mbox,$count,1);
//echo "</pre>";
}
elseif($objTmp->subtype=="JPEG") {
echo $imageName = "iphone-".$timestamp.$timestampCounter.".jpg";
$strFileName = $objTmp->parameters[0]->value;
$strFileType = strrev(substr(strrev($strFileName),0,4));
$fileContent = imap_fetchbody($mbox,$count,2);
$fp = fopen($imageFileOriginal.$imageName, "wb");
$timestampCounter++;
fwrite($fp, imap_base64($fileContent));
fclose($fp);
makeSquareThumbIM($imageName, $imageFileOriginal, $imageFileThumb, '100');
makeMaximumThumbIM($imageName, $imageFileOriginal, $imageFileSmall, '620');
$fields['crDate'] = $timestamp;
$fields['image'] = $imageName;
$fields['email'] = $email;
$fields['description'] = $subject;
echo "<pre>";
print_r($fields);
echo "</pre>";
$db->changeTable($fields, '', TBL_IPHONE);
}
}
//mail markeren voor verwijdering
imap_delete($mbox, $count);
}
//verwijder alle gemarkeerde emails.
imap_expunge($mbox);
imap_close($mbox);
?>
Er zijn nog geen reacties op dit bericht.