Is that possible to extract doc/docx file page wise in php? - php

I have a web form where user needs to upload a document file (doc or docx), in that file there is some formatted data on multiple each page. so I want to extract that data but I also need to know page number as well. That means I want content of each page separately, is it possible?
Thanks

Its not in raw format, so you want this maybe to interpret the code of docx.
https://github.com/PHPOffice/PHPWord Check this.

Related

how to show content of doc file having text and images in a web page using php

I have uploaded the doc files in my server and now i have to show the content of doc files in web page. Now i am not getting any way to show that content as doc may contain images, tables, and other type of texts.
I tried to work with file_get_contents and then using headers but not possible in all ways.
Firstly, .doc/.docx file is not a text file. I don't think with file_get_contents you shall get any normal text character as output.
You can do two things:
Convert the doc/docx to pdf and show in your web page [Try: OfficeToPdf]
Convert the doc/docx to html compatible format using library [Try: PhpWord]
Links
PhpWord: http://phpword.codeplex.com/
OfficeToPdf: http://officetopdf.codeplex.com/
The libraries I mentioned are for example, there are a plenty of libraries available for free. Just Google to get them. Good luck :)
Docx is a zipped file format, so you can't get any information with file_get_contents.
Doc is not zipped, so you will directly get all information in XML format when opening with file_get_contents.
If you want to convert the files for a webviewing, you could use one of the libraries mentioned by #programmer
PhpWord: http://phpword.codeplex.com/
OfficeToPdf: http://officetopdf.codeplex.com/

Using JQuery or PHP to pull latest image?

I was trying to figure out a way to have JQuery (if possible) to display the latest image from a directory, regardless of its file name. Basically, I just want a simple tag to be updated to show the image. I realize this might not be possible with Jquery, so my fallback would be PHP.
I've been trying to research how to do this, but honestly do not know where to start. Any tips to get going would be greatly appreciated,
If you want to do it with JQuery, you can! You only need to add a few lines of logic to your app.
For example, when you add images to that folder, also write a text file with the name of the image just added. Then this text file is going to always have the filename of the last image uploaded. Finally, using JavaScript(with JQuery or anything else) you do one request to the text file and then you do the second request to obtain the image with that filename.
That is just a very basic example to try to share the idea of how to do it, then depending your particular case, you can add or change a lot of details to make this works for your case.
BTW, to do it with PHP, you are going to need to execute a system command, for example 'ls -ltrh' and parse the output to obtain the last filename.
You can use PHP script to get latest modified file in a specific directory.
Code can be found here: Get last modified file in a directory
You then can format that into JSON which can be passed through a jQuery AJAX call http://api.jquery.com/jQuery.ajax/
With those 2 techniques, you can manipulate the data to display the image.

Displaying text content on a PHP image, using text from another site

I have a dynamic image coded in PHP, which is supposed to serve as a display for statistics, using an external site. Each statistic will be displayed using the following general code:
imagettftext($template,10,0,5,35,$black,$font,$statVar1);
...where $statVar1 is the name of the first statistic that will be shown (I have a total of 99 to display).
The only way I know how to do this is to use PHP with JSON, to save the data to a file, and then load them, whenever the image is displayed, but I don't need that sort of data saving in this case, so all I am looking for is just to display whatever the content is on the source page at the same time that the image was loaded.
My JSON solution involved getElementsByTagName, and I would select out the HTML tags and select the right one with item(), but is there a pure PHP solution I could use instead? For instance, if I wanted to visit the DC Vault site, and set my $statVar1 to the Overall Position value of the first team (ie, display '1' on my stat image), what would I do?
If I understand correctly, you want to extract data from another page/site in your PHP code.
The simplest way is to use something like the file_get_contents() with an URL as parameter instead of a regular file path. Learn about PHP URL wrappers.
https://www.php.net/manual/en/wrappers.php
You can than parse returned data to extract what you need.
If the respective site does not provide any export in structured format like XML or JSON, you will need to parse HTML document.
Regular expressions would be a way to go. See the PHP function preg_match.

webcontent save in csv format

I want to read the content from website and save then into a csv file in php, can anyone please tell me how I can do this.
How do you want to save a website's content as csv file? CSV means comma separated values, and it's really easy to save things as csv file but a website's content?
You say "the content from a website" - normally you'll start reading one sites content, which includes html markup, scripts and styles. Or do you only want to get the text contents or some meta data?
If your server supports opening urls via fopen I'd try this one (php.ini option: allow_url_fopen) - otherwise you'll have to use cURL or something.
Here's some more information about reading websites in php.
Regarding the storage of websites as csv I think you should be more precise what you want to achieve.
Regards, Daniel
There's no instant-magic answer for your question. We (You) need to know which website is in question, how the table is presented. If you know everything about your scenario, you should use PHP's DOM functions and parse your table then export it to a CSV.

Is it possible to save a word file in MYSQL database and to view the content "AS IT LOOKS" in the Browser

For example, i am uploading a word file with some FORMATTED contents in the database. The content in the word document is aligned.
I done up to the above level . My issue is how can i able to view the CONTENTS AS IT LOOKS EXACTLY (means the exact formatted contents) IN A BROWSER.
Kindly help me out of this issue.
Thanks in Advance
Fero
You may stream the content in the body of the request as an attachment setting the correct MIME Type. If the user's client is configured to handle the content type it will show (after asking for permissions).
PHP MIME Content Type
Word is a format for word processing, whereas the browser is a client for displaying web pages. So no, you can't. There are some similarities between the two formats, so you can transform between them, but usually at a loss. Since Word is a proprietary format, transforming it to html can be tricky, but you can generally use open office for the job.
Another alternative is, instead of uploading the file, upload the content of the file through the use of a javascript WYSIWYG editor like TinyMCE. Since you will be storing the HTML markups that the editor converts from the formatted contents that you copy-paste in it, it will be very straight-forward to display the contents.
If the content doesn't need to be edited, why not convert it to a .PDF/.JPG on the fly, or do it once upon upload and cache the result?

Categories