Im using the PDF parser that comes with zend framework. Im trying to trying draw an image, but get an error.
function addReklam($reklamblad) //picture.png
{
// kolla hur många sidor som skapats och lägg till en sista reklamsida:
//Öppna fil här, lägg till den i PDF
$fish = 0;
if($this->drawed_lines<52)
{
$this->active_page = $this->pdf->pages[2];
$fish = 1;
}
elseif($this->drawed_lines<92)
{
$this->active_page = $this->pdf->pages[3];
$fish = 2;
}
elseif($this->drawed_lines<132)
{
$this->active_page = $this->pdf->pages[4];
$fish = 3;
}
else
{
$this->active_page = $this->pdf->pages[5];
$fish = 4;
}
//$this->active_page = $this->pdf->pages[5]; // sida 5 är reklamsidan
$image = $this->imageWidthPath($reklamblad);
$this->active_page->drawImage($image, $left, $bottom, $right, $top);
}
I get this message:
Fatal error: Call to undefined method fakturapdf::imageWidthPath() in /data/web/script/pdffaktura/testpdf-txt.php on line 681
EDIT:
I've tried like this now:
function addReklam($reklamblad)
{
// kolla hur många sidor som skapats och lägg till en sista reklamsida:
//Öppna fil här, lägg till den i PDF
$fish = 0;
if($this->drawed_lines<52)
{
$this->active_page = $this->pdf->pages[2];
$fish = 1;
}
elseif($this->drawed_lines<92)
{
$this->active_page = $this->pdf->pages[3];
$fish = 2;
}
elseif($this->drawed_lines<132)
{
$this->active_page = $this->pdf->pages[4];
$fish = 3;
}
else
{
$this->active_page = $this->pdf->pages[5];
$fish = 4;
}
//$this->active_page = $this->pdf->pages[5]; // sida 5 är reklamsidan
$image = Zend_Pdf_Image::imageWithPath($reklamblad);
$this->active_page->drawImage($image, 400, 400, 400, 400);
}
This seems to work fine, I'll get no errors. But is this the correct way to use it? Nothing is printed to the PDF.
Yes it's correct. It's Zend_Pdf_Image::imageWithPath and not $this->imageWidthPath().
It's a static method.
If it helps you, I found it.
Related
I want to display all data I want from Matomo API but I can only display them one by one
I don't know if I should do a for loop and where or how.
My code :
<?php
include 'TabMetrique.php';
$token_auth = '*********';
getMetrique($metrique);
$url = "http://localhost/matomo/";
$url .= "?module=API&method=".getMetrique($metrique)."&idSite=1";
$url .= "&period=month&date=2022-05-14";
$url .= "&format=JSON";
$url .= "&token_auth=$token_auth";
$fetched = file_get_contents($url);
$content = json_decode($fetched,true);
// case error
if (!$content) {
print("No data found");
}
else {
print("<h1>Métrique Matomo</h1>\n");
foreach ($content as $row) {
if ($content == $row){
$contentMetrique = htmlspecialchars($row["label"], ENT_QUOTES, 'UTF-8'); // à changer pour afficher toute les métrique
$hits = $row['nb_visits'];
print("<b>$contentMetrique</b> ($hits visits)<br>\n");
}else{
print("$row<b> action or visit</b>");
}
}
}
?>
My IF condition doesn't work but that's not a problem at the moment
And TabMetrique.php :
<?php
$metrique [0] = 'DevicesDetection.getModel'; // appareil utilisé
$metrique [1] = 'UserCountry.getCountry'; // Pays
$metrique [2] = 'UserCountry.getContinent'; //continent
$metrique [3] = 'UserCountry.getRegion'; // Region
$metrique [4] = 'UserCountry.getCity'; // Ville
$metrique [5] = 'UserId.getUsers'; // recupérer les UsersID
$metrique [6] = 'UserLanguage.getLanguage'; // Langue
$metrique [7] = 'VisitFrequency.get'; // Visiteur récurrent
$metrique [8] = 'VisitsSummary.get';
$metrique [9] = 'VisitsSummary.getVisits'; //visiteur
$metrique [10] = 'VisitsSummary.getUniqueVisitors'; // visiteur unique
function getMetrique($metrique){
return $metrique[9];
}
?>
someone can help me ? thx
Well first remove the function it is unnecessary, all you need is an array and then process it with a forech loop.
code TabMetrique.php
<?php
$metrique[0] = 'DevicesDetection.getModel'; // appareil utilisé
$metrique[1] = 'UserCountry.getCountry'; // Pays
$metrique[2] = 'UserCountry.getContinent'; //continent
$metrique[3] = 'UserCountry.getRegion'; // Region
$metrique[4] = 'UserCountry.getCity'; // Ville
$metrique[5] = 'UserId.getUsers'; // recupérer les UsersID
$metrique[6] = 'UserLanguage.getLanguage'; // Langue
$metrique[7] = 'VisitFrequency.get'; // Visiteur récurrent
$metrique[8] = 'VisitsSummary.get';
$metrique[9] = 'VisitsSummary.getVisits'; //visiteur
$metrique[10] = 'VisitsSummary.getUniqueVisitors'; // visiteur unique
?>
Now a simple foreach loop to control getting the names from the metrique array
<?php
include 'TabMetrique.php';
$token_auth = '*********';
$url = "http://localhost/matomo/?";
$url .= "period=month&date=2022-05-14";
$url .= "&format=JSON&module=API";
$url .= "&token_auth=$token_auth&idSite=1";
foreach ($metrique as $metric) {
//get static part of the url and add dynamic bit to it
// note i moved the dynamic part to be last, that should not matter to the api
$u = $url . "&method=$metric";
$content = json_decode(file_get_contents($u), true);
// case error
if (!$content) {
print("No data found");
} else {
print("<h1>Métrique Matomo</h1>\n");
foreach ($content as $row) {
if ($content == $row){
$contentMetrique = htmlspecialchars($row["label"], ENT_QUOTES, 'UTF-8'); // à changer pour afficher toute les métrique
$hits = $row['nb_visits'];
print("<b>$contentMetrique</b> ($hits visits)<br>\n");
}else{
print("$row<b> action or visit</b>");
}
}
}
}
I have trouble with my static array, i need to update with dynamic array can someone help me ? because will be so hard if i have alot data and i must create 1 by 1.
$kriteria = [C1,C2,C3,C4,C5,C6];
$alternatif = [ALT1,ALT2,ALT,ALT4,ALT5,ALT6,ALT7];
$nEntropy = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
$nEntropy[$i] = (((-1)/log(7)) *(
($probabilitas[0][0]*log($probabilitas[0][0]))+
($probabilitas[1][0]*log($probabilitas[1][0]))+
($probabilitas[2][0]*log($probabilitas[2][0]))+
($probabilitas[3][0]*log($probabilitas[3][0]))+
($probabilitas[4][0]*log($probabilitas[4][0]))+
($probabilitas[5][0]*log($probabilitas[5][0]))+
($probabilitas[6][0]*log($probabilitas[6][0]))
));
}
}
$nEntropy1 = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
$nEntropy1[$i] = (((-1)/log(7)) *(
($probabilitas[0][1]*log($probabilitas[0][1]))+
($probabilitas[1][1]*log($probabilitas[1][1]))+
($probabilitas[2][1]*log($probabilitas[2][1]))+
($probabilitas[3][1]*log($probabilitas[3][1]))+
($probabilitas[4][1]*log($probabilitas[4][1]))+
($probabilitas[5][1]*log($probabilitas[5][1]))+
($probabilitas[6][1]*log($probabilitas[6][1]))
));
}
}
$nEntropy2 = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
$nEntropy2[$i] = (((-1)/log(7)) *(
($probabilitas[0][2]*log($probabilitas[0][2]))+
($probabilitas[1][2]*log($probabilitas[1][2]))+
($probabilitas[2][2]*log($probabilitas[2][2]))+
($probabilitas[3][2]*log($probabilitas[3][2]))+
($probabilitas[4][2]*log($probabilitas[4][2]))+
($probabilitas[5][2]*log($probabilitas[5][2]))+
($probabilitas[6][2]*log($probabilitas[6][2]))
));
}
}
$nEntropy3 = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
$nEntropy3[$i] = (((-1)/log(7)) *(
($probabilitas[0][3]*log($probabilitas[0][3]))+
($probabilitas[1][3]*log($probabilitas[1][3]))+
($probabilitas[2][3]*log($probabilitas[2][3]))+
($probabilitas[3][3]*log($probabilitas[3][3]))+
($probabilitas[4][3]*log($probabilitas[4][3]))+
($probabilitas[5][3]*log($probabilitas[5][3]))+
($probabilitas[6][3]*log($probabilitas[6][3]))
));
}
}
$nEntropyy4 = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
$nEntropy4[$i] = (((-1)/log(7)) *(
($probabilitas[0][4]*log($probabilitas[0][4]))+
($probabilitas[1][4]*log($probabilitas[1][4]))+
($probabilitas[2][4]*log($probabilitas[2][4]))+
($probabilitas[3][4]*log($probabilitas[3][4]))+
($probabilitas[4][4]*log($probabilitas[4][4]))+
($probabilitas[5][4]*log($probabilitas[5][4]))+
($probabilitas[6][4]*log($probabilitas[6][4]))
));
}
}
$nEntropy5 = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
$nEntropy5[$i] = (((-1)/log(7)) *(
($probabilitas[0][5]*log($probabilitas[0][5]))+
($probabilitas[1][5]*log($probabilitas[1][5]))+
($probabilitas[2][5]*log($probabilitas[2][5]))+
($probabilitas[3][5]*log($probabilitas[3][5]))+
($probabilitas[4][5]*log($probabilitas[4][5]))+
($probabilitas[5][5]*log($probabilitas[5][5]))+
($probabilitas[6][5]*log($probabilitas[6][5]))
));
}
}
showb($nEntropy);
showb($nEntropy1);
showb($nEntropy2);
showb($nEntropy3);
showb($nEntropy4);
showb($nEntropy5);
this image for my results
as you can see my code really static and so hard if i have alot data
and also i need my results likes this
EDIT
the answers from Vörös Amadea are correct, but there are still some that are lacking, my second question regarding the results is still in large numbers. is there a way to display it only once?
as u can see on my image before, i need to remove duplicate data so only 1 for each is who will displayed and store it into array.
I have modified a little code from Vörös Amadea because if I don't modify it, I get an error "Undefined variable: probability"
this is the code that I have modified.
for($x=0;$x<1;$x++){
$nth = $x;
$entz = array();
for ($i=0;$i<count($kriteria);$i++)
{
for ($j=0;$j<count($alternatif);$j++)
{
${"entz$nth"}[$i] = (((-1)/log(7)) *(
($probabilitas[0][$nth]*log($probabilitas[0][$nth]))+
($probabilitas[1][$nth]*log($probabilitas[1][$nth]))+
($probabilitas[2][$nth]*log($probabilitas[2][$nth]))+
($probabilitas[3][$nth]*log($probabilitas[3][$nth]))+
($probabilitas[4][$nth]*log($probabilitas[4][$nth]))+
($probabilitas[5][$nth]*log($probabilitas[5][$nth]))+
($probabilitas[6][$nth]*log($probabilitas[6][$nth]))
));
}
}
}
showb(${"entz$nth"});
You can generate variable names in for loops like this.
Just change the value of $how_many_i_want.
$how_many_i_want = 3;
for($x=0;$x<$how_many_i_want;$x++){
generate_entropy($x);
}
function generate_entropy($nth){
$kriteria = ['C1','C2','C3','C4','C5','C6'];
$alternatif = ['ALT1','ALT2','ALT','ALT4','ALT5','ALT6','ALT7'];
${"nEntropy$nth"} = array();
for ($i=0;$i<count($kriteria);$i++){
for ($j=0;$j<count($alternatif);$j++){
${"nEntropy$nth"}[$i] = (((-1)/log(7)) *(
($probabilitas[0][$nth]*log($probabilitas[0][$nth]))+
($probabilitas[1][$nth]*log($probabilitas[1][$nth]))+
($probabilitas[2][$nth]*log($probabilitas[2][$nth]))+
($probabilitas[3][$nth]*log($probabilitas[3][$nth]))+
($probabilitas[4][$nth]*log($probabilitas[4][$nth]))+
($probabilitas[5][$nth]*log($probabilitas[5][$nth]))+
($probabilitas[6][$nth]*log($probabilitas[6][$nth]))
));
}
}
showb(${"nEntropy$nth"});
}
I'm having two errors, can't get this to work...
With the code like this:
<html>
<body>
<?php
/*
Fontes:
- http://blog.clares.com.br/gerando-xml-com-php/
- https://forum.imasters.com.br/topic/482006-resolvido%C2%A0gerar-nomes-aleat%C3%B3rios/
*/
header('Content-type: text/xml; charset=utf-8');
if(empty($_POST["Pergunta"])) {
$pergunta = "";
echo "dar um alert e voltar";
} else {
$pergunta = $_POST["Pergunta"];
}
if(empty($_POST["Resposta"])) {
$resposta = "";
echo "dar um alert e voltar";
} else {
$resposta = $_POST["Resposta"];
$teste = explode("\n",$resposta);
echo '<pre>' . print_r($teste) . '</pre>';
}
/* CHECKBOX
if(isset($_POST['MostrarAIML'])){
//echo "checkbox marcado! <br/>";
//echo "valor: " . $_POST['MostrarAIML'];
$MostrarAIML = true;
}else{
//echo "checkbox não marcado! <br/>";
$MostrarAIML = false;
}
if(isset($_POST['SalvarAIML'])){
//echo "checkbox marcado! <br/>";
//echo "valor: " . $_POST['SalvarAIML'];
$SalvarAIML = true;
}else{
//echo "checkbox não marcado! <br/>";
$SalvarAIML = false;
} */
if(empty($_POST["forma"])) {
$escolhe = "MostrarAIML";
} else if($_POST["forma"]=='MostrarAIML'){
$escolhe = "MostrarAIML";
} else if($_POST["forma"]=='SalvarAIML'){
$escolhe = "SalvarAIML";
}
function nome_aleatorio(){
$tamanho = mt_rand(5,9);
$all_str = "abcdefghijlkmnopqrstuvxyzwABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$nome = "";
for ($i = 0;$i <= $tamanho;$i++){
$nome .= $all_str[mt_rand(0,61)];
}
return $nome;
}
# versao do encoding xml
$dom = new DOMDocument("1.0", "UTF-8");
# retirar os espacos em branco
$dom->preserveWhiteSpace = false;
# gerar o codigo
$dom->formatOutput = true;
# criando o nó principal (root)
$root = $dom->createElement("aiml");
$comentario = $dom->createComment("Copyright ©2017 - FAST.aiml
URL: http://avatar.cinted.ufrgs.br/alunos/fabricio/fastaiml/
Powered by Fabricio Herpich < fabricio_herpich at hotmail.com >
Project coordinator: Liane Margarida Rockenbach Tarouco < liane at penta.ufrgs.br >");
# nó filho (category)
$category = $dom->createElement("category");
# nó filho (pattern) / #setanto a pergunta
$pattern = $dom->createElement("pattern", $pergunta);
# nó filho (template) / #setanto a resposta
$template = array();
for($i = 0; $i < sizeof($teste); $i++){
$template[$i] = $dom->createElement("template", $teste[$i]);
}
# adiciona os nós em aiml
$category->appendChild($comentario);
$category->appendChild($pattern);
for($i = 0; $i < sizeof($template); $i++){
$category->appendChild($template[$i]);
}
# adiciona o nó contato em (root) agenda
$root->appendChild($category);
$dom->appendChild($root);
# busco um nome aleatório
$nome_arquivo = nome_aleatorio();
$dom->save("backup__/" . $nome_arquivo . ".xml");
if($escolhe == "MostrarAIML"){
# imprime o xml na tela
print $dom->saveXML();
}
if($escolhe == "SalvarAIML"){
# imprime o xml na tela
print $dom->saveXML();
# salva o arquivo AIML.xml
header("Content-Disposition: attachment; filename=fastaiml_" . $nome_arquivo . ".xml");
}
?>
</body>
</html>
I'm getting this error:
This page contains the following errors:
error on line 12 at column 18: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.**
I have other php file that works perfectly, where the header() function is after the $nome_arquivo = nome_aleatorio();
But, In this case I don't have the for loops on the code, 'cause I only have one for the file...and in this case I have to put multiple inside the tag...
If I put the header() like the other file, I get:
This page contains the following errors:
error on line 7 at column 18: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.**
how to work around this?
Think of simple profile page. User must editing. So, I've created basic php page. But, it is doesn't upload image. Why is it not uploading? I don't understand.
<?php
if((array_key_exists("degistir",$_GET) && $_GET['degistir'] == "dogru") && (array_key_exists('uyeId',$_GET) && $_GET['uyeId'] == md5(#$_SESSION['uyeGiris_skype'])))
{
if(isset($_POST['duzenlemeBitir']))
{
$uyeUrl_ = "inc/imj/uye/".$_SESSION['uyeGiris_skype'];
if(!is_dir($uyeUrl_)){mkdir($uyeUrl_);
$profilResim = $uyeUrl."/".$FILES['profilResim']['name'];
move_uploaded_file($_FILES['profilResim']['tmp_name'],$profilResim) or die(mysql_error());
$galeri = array();
for($s=1; $s<9; $s++)
{
$uyeUrlLink = $uyeUrl_."/".$_FILES['galeri'.$s]['name'];
$uyeUrlAdi = $_FILES['galeri'.$s]['name'];
move_uploaded_file($_FILES['galeri'.$s]['tmp_name'],$uyeUrlLink) or die(mysql_error());
$galeri[$s] = $uyeUrlLink;
}
if(!isset($_FILES['profilResim']['value']))
{
$_FILES['profilResim']['value'] = $uyeDetay['profilResim'];
}
if(!isset($_FILES['galeri1']['value']))
{
$_FILES['galeri1']['value'] = $uyeDetay['galeri1'];
}
if(!isset($_FILES['galeri2']['value']))
{
$_FILES['galeri2']['value'] = $uyeDetay['galeri2'];
}
if(!isset($_FILES['galeri3']['value']))
{
$_FILES['galeri3']['value'] = $uyeDetay['galeri3'];
}
if(!isset($_FILES['galeri4']['value']))
{
$_FILES['galeri4']['value'] = $uyeDetay['galeri4'];
}
if(!isset($_FILES['galeri5']['value']))
{
$_FILES['galeri5']['value'] = $uyeDetay['galeri5'];
}
if(!isset($_FILES['galeri6']['value']))
{
$_FILES['galeri6']['value'] = $uyeDetay['galeri6'];
}
if(!isset($_FILES['galeri7']['value']))
{
$_FILES['galeri7']['value'] = $uyeDetay['galeri7'];
}
if(!isset($_FILES['galeri8']['value']))
{
$_FILES['galeri8']['value'] = $uyeDetay['galeri8'];
}
$ekle = mysql_query("UPDATE uye SET skype='".$_POST['skype']."', msn='".$_POST['msn']."', facebook='".$_POST['facebook']."', yas='".$_POST['yas']."', boy='".$_POST['boy']."', kilo='".$_POST['kilo']."', hakkinda='".$_POST['hakkinda']."', profil_resim='".$profilResim."', galeri_1='".$galeri[1]."', galeri_2='".$galeri[2]."', galeri_3='".$galeri[3]."', galeri_4='".$galeri[4]."', galeri_5='".$galeri[5]."', galeri_6='".$galeri[6]."', galeri_7='".$galeri[7]."', galeri_8='".$galeri[8]."' WHERE e_posta = '".$_SESSION['uyeGiris_ePosta']."' AND sifre='".$_SESSION['uyeGiris_sifre']."'") or die(mysql_error());
}
}
?>
Notice: This codes have mysql_error() functions but I can't see error the simple profil editing page..
Thank you for your interest.
Good works..
Clerical error..
$uyeUrl = blabla..
if(!is_dir($uyeUrl_)){mkdir($uyeUrl_);}
$profilResim = $uyeUrl_."/".$FILES['profilResim']['name'];
I am currently using an imap stream to get emails from an inbox.
Everything is working fine except I am unsure how to get the body text and title of the email. If I do imap_body($connection,$message) the base 64 equivalent of the email attachment is included in the text.
I am currently using this function to get the attachments.
http://www.electrictoolbox.com/function-extract-email-attachments-php-imap/
Well php imap's function are not fun to work with. A user on this page explains the inconsistencies with getting emails: http://php.net/manual/en/function.imap-fetchbody.php#89002
Using his helpful information I created a reliably way to get an email's body text.
$bodyText = imap_fetchbody($connection,$emailnumber,1.2);
if(!strlen($bodyText)>0){
$bodyText = imap_fetchbody($connection,$emailnumber,1);
}
$subject = imap_headerinfo($connection,$i);
$subject = $subject->subject;
echo $subject."\n".$bodyText;
My solution (works with all types and charset) :
function format_html($str) {
// Convertit tous les caractères éligibles en entités HTML en convertissant les codes ASCII 10 en $lf
$str = htmlentities($str, ENT_COMPAT, "UTF-8");
$str = str_replace(chr(10), "<br>", $str);
return $str;
}
// Start
$obj_structure = imap_fetchstructure($imapLink, $obj_mail->msgno);
// Recherche de la section contenant le corps du message et extraction du contenu
$obj_section = $obj_structure;
$section = "1";
for ($i = 0 ; $i < 10 ; $i++) {
if ($obj_section->type == 0) {
break;
} else {
$obj_section = $obj_section->parts[0];
$section.= ($i > 0 ? ".1" : "");
}
}
$text = imap_fetchbody($imapLink, $obj_mail->msgno, $section);
// Décodage éventuel
if ($obj_section->encoding == 3) {
$text = imap_base64($text);
} else if ($obj_section->encoding == 4) {
$text = imap_qprint($text);
}
// Encodage éventuel
foreach ($obj_section->parameters as $obj_param) {
if (($obj_param->attribute == "charset") && (mb_strtoupper($obj_param->value) != "UTF-8")) {
$text = utf8_encode($text);
break;
}
}
// End
print format_html($text);
You Can also try these
content-type:text/html
$message = imap_fetchbody($inbox,$email_number, 2);
content-type:plaintext/text
$message = imap_fetchbody($inbox,$email_number, 1);