Generate a Doc File with an Image - php

<?php
$docName = "testdoc";
header("Expires: Mon, 26 Jul 2020 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-Type: application/msword; charset=ISO-8859-1");
header("Content-Disposition: attachment; filename=\"".$docName.".doc");
#/ Create and format your text using HTML, its simple stuff ... trial and error ;)
echo '<img src="logo.gif" />';
?>
Soumya Sarkar
Hi I got this following code from google to generate a Doc file by php. But I am unable to put any image there. Can anybody help me with it?

It requires the link, you will need to host the images online in order for the image to be shown on the doc.
Try this and it is working:-
echo "<img src='http://i.imgur.com/MJ5Sa.jpg' />";

Related

Clear site browser cache in php

trying to Clear browser site cache in php,
for firefox browser is working fine, as we want but when i run in chrome it didnt work.
see code,
header('Clear-Site-Data: "cache", "cookies", "storage", "executionContexts"'); //Firefox
// Crome
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header('Clear-Site-Data: "cookies"');
return $this->getSuccessResponse("Token Valid");
I think you can't clear cache from browser perfectly, one only option is you can do manually. There is some code. I hope it will work.
<?php
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

Conversion from excel file which includes russian letters to pdf using php excel

I have a file in excel and I am converting it to pdf using phpexcel. It is displaying russian letters as ????
Here is the code that is responsible for conversion:
public function exportToExcel($phpExcelObject)
{
header("Expires: Mon, 1 Apr 1974 05:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: application/vnd.ms-excel", 'charset=UTF-8');
header("Content-Disposition: attachment; filename=matrix.xls");
$objWriter = new PHPExcel_Writer_Excel5($phpExcelObject);
$objWriter->save('php://output');
}
Could you please help me?
First, check the folder which includes fonts supported by domPDF. Then, If there are any font which ends with .ttf, apply this font-family to the corresponding cells of PhpExcel Object. Then it works.
$sheet->getStyle('A1')->getFont()->setName('dejavu sans');

Php CSV export UTF8 encoding causing incorrect excel format

i tired doing an csv export. I needed two languages (tamil and english) in the sheet using normal headers
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
header ( 'Content-Type: application/vnd.ms-excel') ;
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
echo $content;
This was causing problems in the tamil characters being displayed. But the format of the excel was fine. So i used a UTF8 encoding to display the tamil characters as shown below.
$now = gmdate("D, d M Y H:i:s");
header('Pragma: public');
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Last-Modified: {$now} GMT");
header('Content-Type: text/csv');
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
echo chr(255) . chr(254) . mb_convert_encoding($content, 'UTF-16LE', 'UTF-8');
This helped with the characters and both languages are being displayed fine now but the format of the csv being generated is disrupted. Everything is being displayed in a single column. Is there anyway to solve this?

download file with php

i want to create a link to download an excel file from the root in server computer, using php. so i wrote a simple code as below,
<?php
header("Content-disposition: attachment; filename=example.xls");
header("Content-type: application/vnd.ms-excel");
readfile("example.xls");
?>
it then can be downloaded however when i want to open it, i got the error saying the file i downloaded is in a different format than specified by the file extension. i also tried the same method with jpeg file and didnt get the same error but when i click it, it shows nothing. can someone help me? im not very good with programming. thank you in advance!
Try this
$file='example.xls'; $filesize=filesize($file);
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: inline; filename="'.basename($file).'"');
header("Content-Length: " . $filesize);
$fh = fopen("$file, "rb");
// output file
while(!feof($fh))
{
# output file without bandwidth limiting
print(fread($fh, filesize($file)));
}
fclose($fh);

How to prevent from session restore on back button in ubuntu?

Guys please tell me how to prevent from session restore on back button in ubuntu ?
session_cache_limiter( FALSE );
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate, post-check=0, pre-check=0'");
header("Pragma: no-cache");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
this works in xp but not in ubuntu.

Categories