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
Related
this was my original question I was stuck and tried to solve my problem by trying something and got stuck again
I need to extract name of candidate and his id from a pdf ,so after using pdfparser I extracted the text and downloaded the html page using php
<?php
$filename = 'filename.html';
header('Content-disposition: attachment; filename=' . $filename);
header('Content-type: text/html');
// ... the rest of your file
?>
<?php
// Include Composer autoloader if not already done.
include 'C:\Users\amite\Downloads\pdfparser-master (1)\pdfparser-master\vendor\autoload.php';
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('C:\Users\amite\Desktop\Data\001.ApplicationForm-CSE-2015-1-omokop (3).pdf');
$text = $pdf->getText();
echo $text;
?>
I did this cause the info I need that was on line 12 and 13 of the view source page and this was was with all the pdf's I need ,so after downloading the html file I used the code below to see the source page of html file
<?php
show_source("filename.html");
?>
now when I run the above program I got the source page of html file which I downloaded, now I need to extract data from line 12 and 13 , the output of program looks like this :-
<html>
text
text
text
text
text
text
there are no tags except html tag and info I need is on line 12,13, if you need any clarification please ask me I will tell you.
how should I extract text from line 12,13, if there is another way tell me pls. I am stuck again, if the question is vague I will clarify it or improve it, please help me.
Store the file source into an array with $source = file('filename.html'); and extract line 12 and 13 via array index 11 and 12 like this echo $source[11]; //line 12
Is this what you need?
<?php
$str = "1text
2text
3text
4text
5text
6text
7text
8text
9text
10text
11text
12text
13text
";
$k = array_slice(explode("\n",$str),11,1);
print_r($k);
We are trying to create a webpage in laravel where people are going to be able upload their codefiles to our server, so that other users can watch the code and download it in codefiles if they like it. We however can't figure out the best way to make this happen.
I tried to just let php get a file and echo out the content. this worked well fot html and css, but with php nothing got displayed what so ever. someone mentioned using eval(), however i've read that it is a really bad idea to do so. Another idea would be to stash the code in a database and fetch it from there, which we have tried before, but it sort of over complicated, and avoiding to do so would be prefereable, and instead go directly to i file.
So my question is, do anybody have an idea that might work safely, both for us and our server and for the users.
Something like this:
<?php
// read Codefile
$TheCode = file_get_contents($codefile);
// Print it...
echo htmlentities($TheCode);
?>
Save the php code in a flat file like one with a .dat extension.
then read the file.
$toechp = file(static.dat);
echo $toecho;
You can allow .dat files to be downloaded on browser using headers.
<?php
$file = "http://example.com/static.dat";
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$file\"");
readfile ($file);
?>
and you are done.
I'm trying to save the content of a file into a PDF using html2pdf, but the file has some PHP codes which need to be processed. I made some research and I found out that I had to use output buffering so that the PHP content in the file can be processed. So I did something like:
<?php
require_once('html2pdf.class.php');
ob_start();
require_once('my_file.php');
$content = ob_get_clean();
// force download of $content to a PDF
$html2pdf = new HTML2PDF('P','A3','fr', false, 'ISO-8859-1');
$html2pdf->writeHTML($content);
$html2pdf->Output('file_name.pdf', 'D');
?>
The file my_file.php is the file that has some PHP code and the HTML content that I wanna save to a PDF, and the variable $content is the actual content with the PHP codes processed and everything. This works fine on Apache, but not on IIS.
Does anybody know an alternative way to make this work witout using ouput buffering? I tried file_get_contents('my_file.php'); but my php contents in my_file.php do not get processed when I do so.
Please, I'm looking for ways to do this without output buffering so that it can work on any server. I'm not looking for answers telling me to change my IIS server configuration or to use something else other than html2pdf.
Thanks in advance for any help
If you can modify the contents of my_file.php, you can put all the text into a variable there instead of outputting it directly.
You can use PHP/PDF Library http://php.net/manual/en/book.pdf.php
And follow this example : http://php.net/manual/en/pdf.examples-basic.php
Hope that helps :)
The easiest approach would be to edit my_file.php so that rather than containing HTML it assigns the HTML content to a PHP variable. Then all you need to do is echo the variable.
//other PHP processing goes here, or anywhere else.
$someVar = "hello world";
$myHTML = "<html>My output: $someVar </html>";
echo $myHTML;
It's an ugly way of handling HTML output, and I'm not saying it's good programming, but if you want to avoid editing config files it would be quick and easy.
I can convert html page to pdf and send it via email with out any problem, but I am facing trouble with converting php file to pdf.
is it possible to convert php file to pdf using mpdf or do I need to use some other php class for this?
Thanks!
The option seems to be like, first convert the output of the php file to html file, save it and pass that file to mpdf.
Thought my solution may seem other way round but it worked well for me.
Or otherwise this Link
<?php
$file = '/home/user/Desktop/myfile.html';
$result = file_get_contents("url/of/ur/page");
echo $result; //view source now
file_put_contents($file, $result);
?>
now u can pass this file to mpdf. Realie sorie bt i havnt used mpdf till date. May be this solution works for you.
Also, other option is curl.
test.php code:
$fileloc = 'audio.mp3';
header('Content-type: audio/mpeg');
header("Content-disposition: inline; filename=$filename");
header('Content-Length:'.filesize($fileloc));
readfile($fileloc);
html code:
<iframe src="test.php"></iframe>
here is the updated code that is working.
thanks hafichuk
if anyone knows a way to do this with
<embed> or <object> rather than <iframe>
please share your code or send me a link.
Try changing your content type to audio/mpeg3.
Update 1:
Since it's downloading the file as an attachment, you could also try changing the content-disposition to header('Content-Disposition: inline; filename=audio.mp3');
The reference I found for this was for swf files in the embed tag, however I would imagine that you should do the same.
I know this is old, but I found a simple way to accomplish this, yet it might not be the prettiest, but
here it is!
test.php:
<?php
if (isset($_GET['file'])) {
echo file_get_contents('music.mp3');
exit;
}
<audio src="test.php?file" controls></audio>
You simply extract the file using file_get_contents and output it, using the php file as the sound file, pretty neat :P