Diskuze: Ajax post na php (canvas)
V předchozím kvízu, Online test znalostí JavaScript, jsme si ověřili nabyté zkušenosti z kurzu.
Zobrazeno 3 zpráv z 3.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Online test znalostí JavaScript, jsme si ověřili nabyté zkušenosti z kurzu.
<?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($attachment, '//'):
strrpos($attachment, '/')+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,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . "
boundary=\"{$mime}\"";
$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(base64_encode($data));
$message .= "--{$mime}\n" . "Content-Type: {$fileatt_type};\n" .
" name = \"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" .
" filename = \"{$fileatt_name}\"\n" . "Content-Transfer-Encoding:
base64\n\n" . $data . "\n\n" . "--{$mime}--\n";
if(mail($to, $subject, $message, $headers)) {
echo "File Sent Successfully.";
unlink($attachment); // 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($data,",")+1);
$data = str_replace('data:image/png;base64,', '', $data);
$data = base64_decode($data);
//$file = strtotime(date('D_M_Y:G_i_')) .
base64_encode(random_bytes(5));
$file = time(). base64_encode(random_bytes(5)) . '.png';
file_put_contents('pics/'.$file, $data);
//Sending
$email = $_POST['email'];
trigger_error('bla', E_ERROR);
mail_attachment('lukas@icoiweb.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>
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.
Zobrazeno 3 zpráv z 3.