IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
lukas5895
Člen
Avatar
lukas5895:19.10.2017 19:47

ahoj mám trochu problém mám tenhle kod v konzoli je čistý potřebuju aby se canvas uložil jako png a potom poslal mailem.
$(document).re­ady(function(){
$(".btn-next").click(fun­ction(){
var text = $('input').val();
var canvas = document.getE­lementById("my­Canvas");
var ctx = canvas.getCon­text("2d");

ctx.font = "30px Arial";
ctx.fillText(tex­t,10,50);

var canvasData = canvas.toData­URL("image/png");
$.ajax({
url: 'send.php',
type: 'POST',
data: {
data: canvasData
}

});
});
});

nevidí tam někdo chybu ..? docela to spěchá díky

 
Odpovědět
19.10.2017 19:47
Avatar
lukas5895
Člen
Avatar
lukas5895:19.10.2017 19:55

<?php

function mail_attachment ($from , $to, $subject, $message, $attachment)
{
$fileatt = $attachment; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type

$start = strrpos(
$attachment, '/') == -1 ?
strrpos($attachmen­t, '//'):
strrpos($attachmen­t, '/')+1;

$fileatt_name = substr(
$attachment,
$start,
strlen($attachment)
);

$email_from = $from; // Who the email is from
$email_txt = $message; // Message that the email has in it

$headers = "From: ".$email_from;
$file = fopen($fileatt, 'rb');
$data = fread($file,fi­lesize($fileat­t));
fclose($file);

$semi_rand = md5(time());
$mime = "==Multipart_Bou­ndary_x{$semi_ran­d}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . "
boundary=\"{$mi­me}\"";

$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime}\n" . "Content-Type:text/html;
charset = \"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";

$data = chunk_split(ba­se64_encode($da­ta));

$message .= "--{$mime}\n" . "Content-Type: {$fileatt_type};\n" .
" name = \"{$fileatt_na­me}\"\n" . //"Content-Disposition: attachment;\n" .
" filename = \"{$fileatt_na­me}\"\n" . "Content-Transfer-Encoding:
base64\n\n" . $data . "\n\n" . "--{$mime}--\n";

if(mail($to, $subject, $message, $headers)) {
echo "File Sent Successfully.";
unlink($attachmen­t); // delete a file after attachment sent.
}else {
throw new Exception("Sorry but the email could not be sent. Please go back and try again!");
}
}

header('Content-type: image/png');
//Image receiving
$data = $_POST['data'];
//$data = substr($data,strpos($d­ata,",")+1);
$data = str_replace('da­ta:image/png;ba­se64,', '', $data);
$data = base64_decode($da­ta);
//$file = strtotime(date('D_M_Y:G_­i_')) . base64_encode(ran­dom_bytes(5));
$file = time(). base64_encode(ran­dom_bytes(5)) . '.png';
file_put_conten­ts('pics/'.$fi­le, $data);

//Sending
$email = $_POST['email'];
trigger_error('bla', E_ERROR);

mail_attachmen­t('lukas@icoi­web.cz', $email, 'New image was created', 'New Image created!', ('pics/' . $file));

header("Location: index.html");
?>
<!DOCTYPE html>
<html lang = "en" >
<head>
<meta charset = "UTF-8" >
<title>Sending email...</title>
</head>
<body>

</body>
</html>

 
Nahoru Odpovědět
19.10.2017 19:55
Avatar
Roman
Člen
Avatar
Roman:20.10.2017 13:21

Tobe nefunguji logy? Co to dela? Nic se nevypisuje - jen to nefunguje!? To je popis problemu!
Kod neni vlozen do tagu.
Proc v nem jsou i zakomentova radky?
Je lepsi se vyhnout takovym prasackym zapisum jakym je "\"" a misto toho pouzit " 'hodnota' " a nebo naopak ' "hodnota" '.
Celkovy kod je necitelny a s prominutim prasacky. Vypada jako copy&paste reseni.

 
Nahoru Odpovědět
20.10.2017 13:21
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 3 zpráv z 3.