-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocParser.php
More file actions
50 lines (46 loc) · 1.28 KB
/
DocParser.php
File metadata and controls
50 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* DocParser class
*
* Parses docs using LibreOffice command
*
* @author Jhalak <jhalak1983@gmail.com>
* @copyright Copyright (c) 2012 Tasawr Interactive.
*
*/
class DocParser {
//private $url = 'http://198.101.153.9/docparser/doc_parser.php';
private $url = 'http://localhost/docparser/doc_parser.php';
public function getHtmlFromDocFile($fileName) {
$file = file_get_contents($fileName);
$data = http_build_query(
array(
'file_content' => $file,
'filename' => 'file_name_' . rand(10, 99),
'api_key' => 'e4a2ed88c280c425a1e8add7c0ac5f171be9c4b2ecfe5a881d71e64d14361ac8',
)
);
return $this->doPostRequest($data);
}
public function doPostRequest($data, $optionalHeaders = null){
$params = array(
'http' => array(
'method' => 'POST',
'content' => $data
)
);
if ($optionalHeaders !== null) {
$params['http']['header'] = $optionalHeaders;
}
$ctx = stream_context_create($params);
$fp = @fopen($this->url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $this->url");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $this->url");
}
return $response;
}
}