-
Notifications
You must be signed in to change notification settings - Fork 0
/
savefile.php
58 lines (51 loc) · 1.79 KB
/
savefile.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
$data=json_decode($_POST['data'],true);
$fails=urldecode($data['fails']);
if(!(file_exists($fails) && substr($fails,0,strlen($fails)-strlen(strstr($fails, '/')))=="faili"))
{
echo "Piekļuves kļūda!";
die();
}
$fails=str_replace("faili/txt","faili/xml",$fails);
$celi=explode("/",$fails);
$total=count($celi)-1;
$cels="faili";
for($i=1;$i<$total;$i++)
{
$cels.="/".$celi[$i];
if(!file_exists($cels))
{
mkdir($cels,0777);
}
}
$fails=str_replace(strrchr($fails, '.'),".xml",$fails);
$f=fopen($fails,"w");
fwrite($f,'<?xml version="1.0" encoding="UTF-8"?>'."\n".'<CONTENT>'."\n".'');
fwrite($f,''."\t".'<CATEGORIES>'."\n".'');
foreach($data['category'] AS $category)
{
fwrite($f,''."\t".''."\t".'<CATEGORY id="'.$category['id'].'">'.trim($category['name']).'</CATEGORY>'."\n".'');
}
fwrite($f,''."\t".'</CATEGORIES>'."\n".'');
fwrite($f,''."\t".'<SENTENCE_CATEGORIES>'."\n".'');
foreach($data['sentence_category'] AS $category)
{
fwrite($f,''."\t".''."\t".'<SENTENCE_CATEGORY id="'.$category['id'].'">'.trim($category['name']).'</SENTENCE_CATEGORY>'."\n".'');
}
fwrite($f,''."\t".'</SENTENCE_CATEGORIES>'."\n".'');
fwrite($f,''."\t".'<SENTENCES>'."\n".'');
foreach($data['sentences'] AS $sentence)
{
fwrite($f,''."\t".''."\t".'<SENTENCE CATEGORY="'.$sentence['category'].'">'."\n".'');
fwrite($f,''."\t".''."\t".''."\t".'<TEXT>');
fwrite($f,trim(stripslashes(str_replace("span","WORD",$sentence['text']))));
fwrite($f,'</TEXT>'."\n".'');
fwrite($f,''."\t".''."\t".''."\t".'<COMMENT>');
fwrite($f,trim(stripslashes($sentence['comment'])));
fwrite($f,'</COMMENT>'."\n".'');
fwrite($f,''."\t".''."\t".'</SENTENCE>'."\n".'');
}
fwrite($f,''."\t".'</SENTENCES>'."\n".'');
fwrite($f,'</CONTENT>');
fclose($f);
echo json_encode(Array("success"=>1));