forked from AKSW/csvimport.ontowiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteFile.php
66 lines (58 loc) · 1.83 KB
/
RemoteFile.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2008, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* Remote file class
*
* @category OntoWiki
* @package Extensions
* @subpackage Csvimport
* @copyright Copyright (c) 2010, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
class RemoteFile
{
public function __construct($ckanResourceId) {
$this->ckanResourceId = $ckanResourceId;
$this->uri = $this->getUri($this->ckanResourceId);
$this->localPath = $this->createTempFile();
}
private function getUri($ckanResourceId) {
include_once 'Zend/Http/Client.php';
$client = new Zend_Http_Client();
$client->setUri('http://csv2rdf.aksw.org/getUriByCkanResourceId');
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost('resource_id', $ckanResourceId);
$result = $client->request();
if($result->isError()){
echo $result->getStatus();
} else {
return json_decode($result->getBody());
}
}
private function createTempFile() {
return tempnam(sys_get_temp_dir(), 'csvimport');
}
public function download() {
$newfname = $this->localPath;
$file = fopen ($this->uri, "rb");
if ($file) {
$newf = fopen ($newfname, "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
return $this->localPath;
}
}