Zadejte hledaný výraz...

Jak automaticky posílat fotky z emailu na web?

nadenicek
verified
rating uzivatele
(4 hodnocení)
25. 2. 2017 17:54:19
Dobrý den,
mám fotopast, která mi posílá přes internet fotky do mailu.
Rád bych, aby se fotky z e-mailu automaticky uploadovali na web?
Je to možné?
Poradíte mi, jak na to?
Děkuji
25. 2. 2017 17:54:19
https://webtrh.cz/diskuse/jak-automaticky-posilat-fotky-z-emailu-na-web/#reply1262623
darksir
verified
rating uzivatele
(1 hodnocení)
25. 2. 2017 17:57:32
Třeba bash script který bude vybírat tu schránku a uploadovat přes ftp/ssh. Nebo php script s pop/imap klientem a vhodným filtrem? Možná najdeš hotový php script, který něco takového umí - vytáhnout email přes pop/imap a přílohy uložit do adresáře
25. 2. 2017 17:57:32
https://webtrh.cz/diskuse/jak-automaticky-posilat-fotky-z-emailu-na-web/#reply1262622
Petr Daněk
verified
rating uzivatele
(33 hodnocení)
25. 2. 2017 18:45:28
Ahoj, muzes pouzit script nize, kdysi jsem jej psal pro automaticke uverejneni fotek z jednoho zavodu, kdy je zavodnici poslali na email a ty se samy zverejnovaly. Zobrazeni mam reseno v jinem souboru, ale to asi nepotrebujes, kdyztak napis.
Vybira to vsechny neprectene emaily, muzes to upravit napr
$emails = imap_search($inbox,'FROM "nekdo@nekdo.cz"');
ini_set('display_errors', 1);
error_reporting(-1);
header("Content-Type: text/html; charset=utf-8");
set_time_limit(240);
function autokonverze($msghead, $msgtext) {
preg_match("/charset=('|")?(+)('|")?/s", $msghead, $tmp);
return iconv($tmp, "UTF-8", $msgtext);
}
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'neco@neco.cz';
$password = 'tajneheslo';
/* try to connect */
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox, 'UNSEEN');
$povolenePrilohy = array('jpg', 'png', 'gif', 'jpeg', 'jpe');
function get_decode_value($message, $encoding) {
switch ($encoding) {
case 0:case 1:$message = imap_8bit($message);
break;
case 2:$message = imap_binary($message);
break;
case 3:case 5:$message = imap_base64($message);
break;
case 4:$message = imap_qprint($message);
break;
}
return $message;
}
/* if emails are returned, cycle through each... */
if ($emails) {
$rozeznano = 0;
$nerozeznano = 0;
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach ($emails as $email_number) {
echo '
----------- EMAIL CISLO '.$email_number.'------------------------
';
$attachments = array();
$structure = imap_fetchstructure($inbox, $email_number);
//$overview = imap_fetch_overview($inbox,$email_number,0);
$header = imap_headerinfo($inbox, $email_number);
$fromaddr = $header->from->mailbox . "@" . $header->from->host;
$parts = $structure->parts;
print_r($parts);echo '

'."nn";
$fpos = 2;
for ($i = 0; $i < count($parts); $i++) {
$attachments = array(
'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if ($structure->parts->ifdparameters) {
foreach ($structure->parts->dparameters as $object) {
if (strtolower($object->attribute) == 'filename') {
$attachments = true;
$attachments = $object->value;
}
}
}
if ($structure->parts->ifparameters) {
foreach ($structure->parts->parameters as $object) {
if (strtolower($object->attribute) == 'name') {
$attachments = true;
$attachments = $object->value;
}
}
}
echo 'i je '.$i.' - ';
print_r($attachments);
if ($attachments) {
$attachments = imap_fetchbody($inbox, $email_number, $i + 1);
/* 4 = QUOTED-PRINTABLE encoding */
if ($structure->parts->encoding == 3 || $structure->parts->encoding == 5) {
$attachments = base64_decode($attachments);
}
/* 3 = BASE64 encoding */ elseif ($structure->parts->encoding == 4) {
$attachments = quoted_printable_decode($attachments);
}
}
$part = $structure->parts;
if ($part->disposition == "ATTACHMENT") {
$ext = $part->subtype;
$params = $part->dparameters;
$filename = $part->dparameters->value;
$body = "";
$data = "";
$body = imap_fetchbody($inbox, $email_number, $fpos);
$attachments = true;
$attachments = $filename;
$attachments = get_decode_value($body, $part->type);
$fpos++;
}
}
/* iterate through each attachment and save it */
foreach ($attachments as $attachment) {
if ($attachment == 1) {
echo 'priloha je ' . $attachment . ' - ' . $attachment . '
';
$filename = $attachment;
if (empty($filename))
$filename = $attachment;
if (empty($filename))
$filename = time() . ".dat";
/* prefix the email number to the filename in case two emails
* have the attachment with the same file name.
*/
$pripona = substr($filename, strrpos($filename, '.'), 4);
echo 'pripona je '.$pripona;
if (!in_array(strtolower(substr($pripona,1)), $povolenePrilohy)) {
echo '!!!nepovolena priloha!!!'.substr($filename, strrpos($filename, '.'), 3);
continue;
}
// nacteme poradove cislo a zvetsime jej o 1
$cislo = file_get_contents(dirname(__FILE__).'/data.dat');
$cislo++;
file_put_contents(dirname(__FILE__).'/data.dat', $cislo);
$newName = str_replace('@', '__', $fromaddr);
$filename = str_pad( $cislo, 5, "0", STR_PAD_LEFT ).'-'.$newName.$pripona;
$dst = dirname(__FILE__) . '/img_1/' . $filename;
echo '---- UKLADAM PRILOHU POD NAZVEM '.$filename;
file_put_contents($dst, $attachment);
}
}
/* get information specific to this email */
// $overview = imap_fetch_overview($inbox,$email_number,0);
// $message = imap_fetchbody($inbox,$email_number,'0');
//$message = iconv('iso-8859-2','UTF-8',$message);
/* output the email header information */
// $output.= '
';
// $output.= ''.$overview->subject.' ';
// $output.= ''.$overview->from.'';
// $output.= 'on '.$overview->date.'';
// $output.= '
';
//
/* output the email body */
// $output.= '
'.$message.'
';
//$head=imap_fetchbody($inbox,$email_number,0);
// $msg=quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));
//echo nl2br(autokonverze($head, $msg));
//$message = iconv('iso-8859-2','UTF-8',$msg);
} // end of foreach
}
/* close the connection */
imap_close($inbox);
25. 2. 2017 18:45:28
https://webtrh.cz/diskuse/jak-automaticky-posilat-fotky-z-emailu-na-web/#reply1262621
Pro odpověď se přihlašte.
Přihlásit