Can anyone help me to create simple .rtf file using php? For example: I have a page:
<table>
<tr><td>ID</td><tr><td>sth</td></tr>
<tr><td>1</td><tr><td>sth1</td></tr>
<tr><td>1</td><tr><td>sth1</td></tr>
<tr><td>1</td><tr><td>sth1</td></tr>
</table>
I want to create a .rtf file with this table to let user to edit it using program like MS Word. I was trying with this: http://books.msspace.net/mirrorbooks/php5/067232511X/ch28lev1sec1.html but it did not help me.
// $rtf holds your complete file data
// save file on your server 1st
file_put_contents('/path/to/outfile.rtf', $rtf);
// then offer it as download
header("Content-type: application/rtf");
echo file_get_contents("/path/to/outfile.rtf");
exit();
Related
I am new to PHP development. I am creating excel.xls using the mentioned header information, whereas it is saving as xls at default download folder. Actually, when I click export link, this test.xls file should be saved to www/data/ folder instead of downloading it.
How can I give path for new location to save file using PHP dynamically?
code as follows:
$file = "test.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment;Filename=$file");
code end
Please help if possible.
Thanks in advance.
Best regards,
Balraj
You can use file_put_contents in PHP.
$file = "path/test.xls";
$data = "Keep your data into this variable";
file_put_contents($file,$data);
file_put_contents is wrapper for fopen,fwrite,fclose.For more information check here
Good morning.
I have a test.html file. I would like to convert into test.xlsx using php.
Now, I could create test.xls file using php, whereas it is having only html tags due to that this file could not open directly in excel and it shows extension error. so if the file is having test.xlsx format gets opened smoothly.
I did not know that how to proceed further to get an expected results.
Please help if possible.
Thanks in advance.
Best regards,
Balraj
Use PHPExcel_Reader_HTML function of PHPExcel
In the last few hours I found script for php which converts a .doc file to a .html file but I've not been successful yet.
I just made some simple code for it, like this:
<?php
header("Content-type: application/html");
header("Content-Disposition: attachment;Filename=as.html");
echo $content = readfile('abc.doc');
?>
It makes an output like the one shown below in the image.
any other way to do this ? as same to same as .doc file ?
Did you already search for a solution? I just found this link, perhaps it might help you:
http://www.daniweb.com/web-development/php/threads/130342/convert-.doc-to-html-or-txt-on-fly-during-upload-with-php
I don't know whether this is happening thing or not. Anyways, my problem is
I have log function in my website, from where the Admin can view or visit the locations where the end users have visited. --> This is simple PHP
Now, if he wants to export the log he can but the exported CSV dont have links to the loations.
Hope you got.
I am posting code for your ref:
$contents="Sr.No,User_Type,Location\n";
$add = "select * from log_table order by id";
$user_query = mysql_query($add);
while($row = mysql_fetch_array($user_query))
{
$contents.=$row[log_id].",";
$contents.=$row[Type].",";
$contents.="<a href='$row[location]'>".$row[location]."</a>\n";
}
Header("Content-Disposition: attachment; filename=export.csv");
print $contents;
I had tried putting tag around Location. But it is not working.
What I Expect is
And What I got is
Advance Thanks =)
Excel isnt smart enough to handle CSV links. But is smart enough to handle regular HTML tables.
just output something like the following to a file called output.xls:
<table border=1>
<tr>
<td>1</td>
<td>employee</td>
<td><a href='http://www.example.com'>example</a></td>
</tr>
</table>
Excel will give you a notice that the file is not in the expected format, but if you confirm that you want to open it, you get what you want. Added bonus is that you can also use colors, width/height etc. For an admin that might be enough.
Another bonus is that you dont have to worry about different excel locales where some CSV require ; and others require ,
CSV doesn't support this type of formatting. That is, CSV is plain text. Microsoft Excel isn't automatically converting the links to be clickable.
If you want this, you will have to use an XLS Builder or some equivalent for whichever software you're looking to open it in.
Also, don't try to write your own CSV. Use fputcsv() if your'e going to continue working with a CSV format.
I need to find a certain key in a pdf file. As far as I know the only way to do that is to interpret a pdf as txt file. I want to do this in PHP without installing a addon/framework/etc.
Thanks
You can certainly open a PDF file as text. PDF file format is actually a collection of objects. There is a header in the first line that tells you the version. You would then go to the bottom to find the offset to the start of the xref table that tells where all the objects are located. The contents of individual objects in the file, like graphics, are often binary and compressed. The 1.7 specification can be found here.
I found this function, hope it helps.
http://community.livejournal.com/php/295413.html
You can't just open the file as it is a binary dump of objects used to create the PDF display, including encoding, fonts, text, images. I wrote an blog post explaining how text is stored at http://pdf.jpedal.org/java-pdf-blog/bid/27187/Understanding-the-PDF-file-format-text-streams
Thank you all for your help. I owe you this piece of code:
// Proceed if file exists
if(file_exists($sourcePath)){
$pdfFile = fopen($sourcePath,"rb");
$data = fread($pdfFile, filesize($sourcePath));
fclose($pdfFile);
// Check if file is encrypted or not
if(stripos($data,$searchFor)){ // $searchFor = "/Encrypt"
$counterEncrypted++;
}else{
$counterNotEncrpyted++;
}
}else{
$counterNotExisting++;
}