how to use PHP to write the PDF? - mpdf

It doesn't display ite1 value in the pdf. Why? Could you please, correct my mistake?
<?php
set_include_path($_SERVER['DOCUMENT_ROOT'] .'/mpdf/');
require('mpdf.php');
$n = 0;
$mpdf=new mPDF();
require_once('../../includes/common.php');
$result = mysql_query("SELECT * from sgc where year = '2010'") or die(mysql_error());
$row=mysql_fetch_array($result);
$nric=$row['nric'];
$row=mysql_fetch_array($result);
$meta_ite=$row['meta_ite'];
$mpdf->WriteHTML('<p>Hello World</p>');
$html1 = '<table>
<tr>
<td width="388">Module Description</td>
<td width="111"><div align="center">Grade</div></td>
<td width="92"><div align="center">Earned</div></td>
<td width="96"><div align="center">Authority</div></td>
<td width="74"><div align="center">Series</div></td>
</tr>';
$unser = $meta_ite;
$unser = unserialize($unser);
$count = count($unser);
for($j=0;$j<$count;$j++)
{
$ite1 = $unser[$i][0];
//print_r ($unser[$i][0]."--".$unser[$i][1]."--".$unser[$i][2]);
$html1 .= '<tr><td width="388">'.$nric.'</td>
<td width="111">'.$count.'</td>
<td width="92"><div align="center">'.$ite1.'</div></td>
<td width="96">ITE</td>
<td width="74">2010</td>
</tr>';
}
$html1 .= '</table>';
$mpdf->WriteHTML($html1);
$mpdf->Output('filename.pdf','D');
?>

first you include your mpdf file
require_once('./mpdf/mpdf.php');
also open debug functionality to see the error.
$mpdf->debug = true;
Note: ensure that you have complete permission (777 or 755) for the following folders on server:
/ttfontdata/
/tmp/
/graph_cache/

Related

I need to create a table on 2 different Page on Dom PDF Using PHP for loop?

I have tried to Create a Table using DOM PDF but uncertainly I got error of syntax token error, Can any body help me to figure out this issue.
Below is my code of for loop which i have used inside the $html variables.
$html = "<html></head>
<body>
<main>
<table>
<tr>
<th '>Year</th>
<th '>Age</th>
<th align='center'>Saving</th>
<th >Expenses</th>
</tr>"
for ($year=0; $year < 15; $year++) {
$html.=
'<tr class="table_row">
<td align="center">'.$year.'</td>
<td align="center">'.$table_data['age'][$year].'</td>
<td align="center">'.$table_data['savings'][$year].'</td>
<td align="center">'.$table_data['expenses'][$year].'</td>
</tr>';
}
" </table>
</main>
</body>
</html>";
You need to create two pdf & use 2 foreach loops on both pdf to get the data as you need.
Try this solution. it works for me.

Concrete5.8 Express Object could not be converted to String

Following the guide here
http://documentation.concrete5.org/developers/express/using-the-express-entry-block-to-output-entry-data
I am able to create the same results but if I change the example and attempt to use the attribute of an express object which is a file link or a date field the view block returns the following error
"Object of class DoctrineProxies__CG__\Concrete\Core\Entity\File\File could not be converted to string"
Can the below code be modified to resolve this or is this a core issue?
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
if (isset($entry) && is_object($entry)) {
$drawings = $entry->getDrawings();
?>
<table id="datatable", class="table">
<thead>
<tr>
<th>Drawing Name</th>
<th>Drawing Number</th>
<th>Revision</th>
<th>Revision Date</th>
<th>Category</th>
<th>PDF</th>
</tr>
</thead>
<tbody>
<?php if (count($drawings)) {
foreach($drawings as $drawing) { ?>
<tr>
<td><?=$drawing->getDrawingName()?></td>
<td><?=$drawing->getDrawingNumber()?></td>
<td><?=$drawing->getRevision()?></td>
<td><?=$drawing->getDrawingRevisionDate()?></td>
<td><?=$drawing->getDrawingCategory()?></td>
<td><?=$drawing->getDrawingPdf()?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6">No drawings found.</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
the problem comes from this line:
<?=$drawing->getDrawingPdf()?>
what getDrawingPdf() is returning is a file object so it cannot be output to the screen like a simple string. First, you would have to extract a string from it. For instance, the following code would extract the file name and show it.
<?php
$drawingPdf = $drawing->getDrawingPdf();
$pdfFileName = is_object($drawingPdf)? $drawingPdf->getFileName() : '';
?>
<td><?=$pdfFileName?></td>
What this code does is first get the file object which you already had in your code.
Then if we have a proper file object, get the file name. If it's not a proper file object (you never now it might have been deleted) we return and empty string.
And finally, we output our string $pdfFileName (which is either the filename or an empty string) in your table.
Hope this helps

Knockoutjs - Set CSS class based on value in array

here is the html table I am working on:
<tbody data-bind="foreach: xusers.list">
<tr data-bind="css:{'approved-false' : member()==1 }">
<td data-bind="text: member"></td>
<td data-bind="text: expired"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
</tr>
</tbody>
The value of the array item member displays in the table just fine but my css call is not working no matter what syntax I have tried. I just want to apply this class if member is true (member contains either 1 or 0).
What am I missing?
Additional Code - Am I overwriting observable?...Here is the only place anything is written to the array.
if (!data) {
...
}
else {
if (data.length) {
var curItem;
for (var i=0; i<data.length; i++) {
curItem = new xuser();
curItem.name = data[i].name;
curItem.email = data[i].email;
curItem.city = data[i].city;
curItem.region = data[i].region;
curItem.country = data[i].country;
curItem.expires = data[i].expires;
curItem.member = data[i].member;
curItem.expired = data[i].expired;
xusers.list.push(curItem)
totalRecs = data[i].TotalCount;
}
}
} // if (!data)/else
You were close, just had it backward: see http://knockoutjs.com/documentation/css-binding.html
<tbody data-bind="foreach: xusers.list">
<tr data-bind="css:{'approved-false': member() == 1 }">
<td data-bind="text: member"></td>
<td data-bind="text: expired"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
</tr>
</tbody>
You are also overwriting your observables, see below (this assumes that all fields on curItem are observables, update your own as needed):
if (!data) {
...
}
else {
if (data.length) {
var curItem;
for (var i=0; i<data.length; i++) {
curItem = new xuser();
curItem.name(data[i].name);
curItem.email(data[i].email);
curItem.city(data[i].city);
curItem.region(data[i].region);
curItem.country(data[i].country);
curItem.expires(data[i].expires);
curItem.member(data[i].member);
curItem.expired(data[i].expired);
xusers.list.push(curItem)
// this should probably be somewhere else
totalRecs = data[i].TotalCount;
}
}
} // if (!data)/else

Zend_mail send duplicate attachment

I am using phpexcel library with zend framwork.
I want to send mail to user with excel file attachment, all are working good but mail send with two attachment one is duplicate, i dont know why.
here is my function which is used to export excel and send it to user
public function exportandmail($name = NULL) {
if ($name === NULL) {
$name = 'excel_' . date('Y_m_d');
}
$name = $name.'.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($this->_excel, 'Excel2007');
$objWriter->save("public/uploads/Mailexcel/".$name);
$message="<table width='90%' align='center' >
<tr>
<th height='15' style='background-color:#037296;padding:10px;color:#FFFFFF' align='left'>excel</th>
</tr>
<tr>
<td style='padding:10px'><strong>Please find the attachment. </strong>
</td>
<tr>
<td style='padding:10px'>
Thanks,
</td>
</tr>
</table>";
$mail = new Zend_Mail();
$mail->setBodyHtml($message);
$mail->setFrom('sender#gmail.com', 'sender');
$mail->addTo('user#gmail.com');
$mail->setSubject('find attachment');
$fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
$file = $mail->createAttachment($fileContents);
$file->filename = "excel.xlsx";
$mail->addAttachment($file);
$mail->send();
exit;
}
Thanks in advance.
I got the solution,
In my code, i use both createAttachment and addAttachment, thats why my mail send with duplicate attachment.
Remove addAttachment and its working fine.
$fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
$file = $mail->createAttachment($fileContents);
$file->filename = "excel.xlsx";
$mail->addAttachment($file); // Remove this
$mail->send();

image upload in WordPress admin option page not working

i working on plugin that has in back-end to add url of of site or post and short description and in front end show then in a widget,i have button for small image of post to be uploaded but it didi't work out but same code work fine in normal php...
$upload_errors = array(
// http://www.php.net/manual/en/features.file-upload.errors.php
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
// process the form data
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$upload_dir = "uploads";
// You will probably want to first use file_exists() to make sure
// there isn't already a file by the same name.
// move_uploaded_file will return false if $tmp_file is not a valid upload file
// or if it cannot be moved for any other reason
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) {
$message = "File uploaded successfully.";
} else {
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}
this is the form used to upload image
<form action='' method='post' name="text_form" onsubmit="return Blank_TextField_Validator()" enctype="multipart/form-data">
<table class='form-table'><tr valign='top'>
<th scope='row'><lable for='new_Directory_name'>Enter the Title:</lable></th>
<td><input type='text' id='newtextchange' name='newtextchange' size="100" /></br></td>
</tr>
<tr>
<th scope='row'><lable for='new_Directory_name'>Enter the Description:</lable></th>
<td><textarea rows="4" cols="50" name='textarea1'>
</textarea></br></td>
</tr>
<tr>
<th scope='row'><lable for='new_Directory_name'>Enter the URL:</lable></th>
<td><input type='text' id='newtextchange1' name='newtextchange1' size="100" /></br></td>
</tr>
<tr>
<th scope='row'><lable for='new_Directory_name'>Upload image:</lable></th>
<td> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /><input type="file" name="file_upload" /><br><br><input id='addtobow' class='button-secondary action' type='submit' value='Add to Best of web' name='submit'/></td>
</tr>
</table>
</form>
You should look at wp_handle_upload for this one.
The example given there is very usefull.
To save the url you can use the following lines:
$upload_overrides = array( 'test_form' => false );
$source = wp_handle_upload( $_FILES['file'], $upload_overrides );
if ( $source )
$input = serialize( $source );
Hope it helps!
problem is with the file upload url and this is how i fix it..,now it is working fine...
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
//$upload_dir = "D:\softwares_installed\wamp\www\wordpress\wp-content\plugins\bestofweb\uploads";
$upload_dir =ABSPATH . "wp-content/plugins/bestofweb/uploads";
$up_urlp1="/wp-content/plugins/bestofweb/uploads";
// You will probably want to first use file_exists() to make sure
// there isn't already a file by the same name.
// move_uploaded_file will return false if $tmp_file is not a valid upload file
// or if it cannot be moved for any other reason
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) {
//$message = "File uploaded successfully.";
//echo $upload_dir."/".$target_file;
//echo bloginfo('wpurl');
$up_url= $up_urlp1."/".$target_file;
//echo $up_url;
//if($message == "File uploaded successfully.")
// {
// $imgpath=$upload_dir.
// }
} else {
$error = $_FILES['file_upload']['error'];
// $message = $upload_errors[$error];
}

Resources