-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsentiBank.php
58 lines (47 loc) · 1.27 KB
/
sentiBank.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
<?php
function downloadFile ($url, $path) {
$newfname = $path;
$file = fopen ($url, "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);
}
}
$mainpath = '/home/ubuntu/memex/';
$savepath = $mainpath . 'img/';
$image_url = $_GET['url'];
$name = basename($image_url);
$fullname = $savepath . $name;
$pos = strrpos($fullname, ".");
if ($pos === false) { // note: three equal signs
// not found...
return;
}
$fullnamet = substr_replace($fullname, "_" . Rand(), $pos, 0);
downloadFile($image_url,$fullnamet);
$output = shell_exec("md5sum " . $fullnamet );
list($md5, $tmp) = split(" ", $output);
$fullname = substr_replace($fullname, "_" . $md5, $pos, 0);
if (file_exists($fullname)) {
//echo "The file $filename exists";
unlink($fullnamet);
} else {
//echo "The file $filename does not exist";
rename($fullnamet, $fullname);
}
shell_exec("cd " . $mainpath . " && export LD_LIBRARY_PATH=/usr/local/cuda/lib64 && python sentiBank.py " . $fullname );
$outname = substr_replace($fullname, ".json", -4, 4);
$fout = fopen ($outname, "rb");
if ($fout) {
echo fread($fout,filesize($outname));
}
?>