Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 238 lines (230 sloc) 6.884 kb
19ef3b3 @sucaritas DataStorage First Commit
authored
1 <?
2 error_reporting(E_ALL ^ E_NOTICE);
3 error_reporting(E_ALL); ini_set('display_errors', 1);
4 ignore_user_abort(false);
5 $ep = "../Global/";
6 include "../Global/MySQL.php";
7
8 $h = fopen("./up.txt",'w');
9 //fwrite($h,"-------- REQUEST FILES-----------------------------------------\n");
10 //fwrite($h,"\n".print_r($_FILES,true));
11 //fwrite($h,"-------- REQUEST -----------------------------------------\n");
12 //fwrite($h,"\n".print_r($_REQUEST,true));
13 //fwrite($h,"-----------------------------------------------------\n");
14
15 print "<pre>";
16 print_r($_REQUEST);
17 print "</pre>";
18
19 $sk = $_REQUEST["sk"];
20 if($_REQUEST["Set"]=="head" || $_REQUEST["Set"]=="foot")
21 {
22 $ObjID = $_REQUEST["NID"];
23 $ObjType = "NID";
24 $Role = 8; //Modify Data Node
25 $Auth = AuthForObject($sk,$ObjType,$ObjID,$Role);
26 if(!$Auth)
27 {
28 print "Access Denied";
29 //fwrite($h,"\nAccess Denied:\n");
30 //fwrite($h,"\nUsr:".$_REQUEST["Usr"]);
31 //fwrite($h,"\nPass:".$_REQUEST["Pass"]);
32 //fwrite($h,"\nObjType:".$ObjType);
33 //fwrite($h,"\nObjID:".$ObjID);
34 //fwrite($h,"\nRole:".$Role);
35 exit();
36 }
37 }
38 else
39 {
40 $ObjID = $_REQUEST["RID"];
41 $ObjType = "RID";
42 }
43
44 $Role = 11; //Add Files
45 $Auth = AuthForObject($sk,$ObjType,$ObjID,$Role);
46 if(!$Auth)
47 {
48 print "Access Denied";
49 //fwrite($h,"\nAccess Denied");
50 exit();
51 }
52 //print "r=".rand(0,1000);
53
54 $PathArray = array();
55 $NID = $_REQUEST["NID"];
56 if($_REQUEST["Set"]=="head" || $_REQUEST["Set"]=="foot")
57 $path = $__HeadFootServerPath;
58 else
59 $path = GetPathForNode($NID,$PathArray)."/";
60
61 foreach($_FILES as $key=>$val)
62 {
63
64 $date = date("Y-m-d");
65 /////// UNIQUE NAME ///////
66 $NewName = ereg_replace("[ ()]","",$_FILES[$key]['name']);
67 $NewName = strtolower($NewName);
68 if(file_exists($path.$_REQUEST["RID"]."_".$date."_".$NewName))
69 {
70 $count = 1;
71 while((file_exists($path.$date."_".$count."_".$NewName)))
72 $count++;
73 $FileName = $_REQUEST["RID"]."_".$date."_".$count."_".$NewName;
74 }
75 else
76 $FileName = $_REQUEST["RID"]."_".$date."_".$NewName;
77 ////////////////////////////
78 //fwrite($h,"\nTrying to Move File to:".$path.$FileName);
79 if (move_uploaded_file($_FILES[$key]['tmp_name'], $path.$FileName))
80 {
81 //fwrite($h,file_exists($path.$FileName)?"yes it exists":"no this sucks...");
82 //fwrite($h,"\nMoved File:".$path.$FileName);
83 if($_REQUEST["Set"]=="head")
84 {
85 SetHeaderImg($NID,$FileName);
86 }
87 else if($_REQUEST["Set"]=="foot")
88 {
89 SetFooterImg($NID,$FileName);
90 }
91 else if($_REQUEST["Set"]=="REC")
92 {
93 $Size = filesize($path.$FileName);
94 $FileTypeA = explode(".", $FileName);
95 $FileType = $FileTypeA[1];
96 if(empty($_REQUEST["OCR"]) || $_REQUEST["OCR"]=="TRUE")
97 {
98 $CMD = "tesseract ".$path.$FileName." ".$path.$FileName." -l spa";
99 $output = array();
100 $result = exec(escapeshellcmd($CMD),$output);
101 //fwrite($h,"\nCMD:".$CMD);
102 //fwrite($h,"\noutput:".print_r($output,true));
103 //fwrite($h,"\nResult:".$result);
104 $pspellDictionary = pspell_new("en",'american','','',PSPELL_FAST);
105 //fwrite($h,"\npspell_link:".$pspellDictionary);
106 if(file_exists($path.$FileName.".txt"))
107 $lines = file($path.$FileName.".txt");
108 else
109 $lines = file($path.$FileName);
110 //fwrite($h,"\nExtracted Lines");
111 $extractedWords = "";
112 $NewWord = "";
113 foreach ($lines as $line_num => $line)
114 {
115 for($i=0; $i<strlen($line); $i++)
116 {
117 $c = $line[$i];
118 $o= ord(strtolower($c));
119 if( (($o>=97)&&($o<=122)) || (($o>=48)&&($o<=57)) || ($o==45)) //a to z || 0 to 9
120 $NewWord .=$c;
121 else if($o!=0)
122 {
123 if(is_numeric($NewWord))
124 {
125 $extractedWords.= $NewWord." ";
126 }
127 else if(strlen($NewWord)>3)
128 {
129 if(!stristr($extractedWords,$NewWord))
130 {
131 $ValidWord=true;
132 //fwrite($h,"\nlooking at word:".$NewWord);
133 if(HasNum($NewWord))
134 {
135 //fwrite($h," <=== Word is a mix");
136 }
137 else if(pspell_check($pspellDictionary, $NewWord))
138 {
139 //fwrite($h," <=== Word is spelled correctly");
140 $extractedWords.= $NewWord." ";
141 }
142 else
143 {
144 //fwrite($h," <=== Word is miss spelled");
145 $TempWord = "";
146 $BestMatch = 3;
147 $Suggestions = pspell_suggest($pspellDictionary,$NewWord);
148 //fwrite($h,"\nSugested words:\n");
149 foreach($Suggestions as $k=>$suggested)
150 {
151 $src = btlfsa($NewWord,$suggested);
152 //fwrite($h,"\t".$suggested.":".$src."\n");
153 if($BestMatch<$src)
154 {
155 $BestMatch = $src;
156 $TempWord = $suggested;
157 }
158 }
159 if(!empty($TempWord))
160 $extractedWords.= $TempWord." ";
161 //else
162 // $extractedWords.= $NewWord." ";
163 }
164 }
165 }
166 $NewWord = "";
167 }
168 }
169 }
170 unlink($path.$FileName.".txt");
171 //fwrite($h,"\nProcesed Lines");
172 }
173 $md5 = md5_file($path.$FileName);
174 try
175 {
176 //fwrite($h,"\ninserting words:".$extractedWords."\n");
177 //fwrite($h,"\nInserting Lines");
178 $ins = InsertFileToRecord($_REQUEST["NID"],$_REQUEST["RID"],$_FILES[$key]['name'],$FileName,$path,$Size,$FileType,$_REQUEST["Usr"],esc($extractedWords),$md5,$_REQUEST["RID"]);
179 //fwrite($h,"\nInsert:".$ins);
180 }
181 catch(Exception $e)
182 {
183 unlink($path.$FileName);
184 //fwrite($h,"\nError:".$e->getMessage());
185 }
186 //$path.$FileName
187 }
188 }
189 else
190 fwrite($h,"\nFailed to move File:".$NewName);
191 }
192 function btlfsa($word1,$word2)
193 {
194 $score = 0;
195 // For each char that is different add 2 to the score
196 // as this is a BIG difference
197 $remainder = preg_replace("/[".preg_replace("/[^A-Za-z0-9\']/",' ',$word1)."]/i",'',$word2);
198 $remainder .= preg_replace("/[".preg_replace("/[^A-Za-z0-9\']/",' ',$word2)."]/i",'',$word1);
199 $score = strlen($remainder)*2;
200 // Take the difference in string length and add it to the score
201 $w1_len = strlen($word1);
202 $w2_len = strlen($word2);
203 $score += $w1_len > $w2_len ? $w1_len - $w2_len : $w2_len - $w1_len;
204 // Calculate how many letters are in different locations
205 // And add it to the score i.e.
206 //
207 // h e a r t
208 // 1 2 3 4 5
209 //
210 // h a e r t a e = 2
211 // 1 2 3 4 5 1 2 3 4 5
212 //
213 $w1 = $w1_len > $w2_len ? $word1 : $word2;
214 $w2 = $w1_len > $w2_len ? $word2 : $word1;
215 for($i=0; $i < strlen($w1); $i++)
216 {
217 if ( !isset($w2[$i]) || $w1[$i] != $w2[$i] )
218 {
219 $score++;
220 }
221 }
222 return $score;
223 }
224 function HasNum($var)
225 {
226 for ($i=0;$i<strlen($var);$i++)
227 {
228 $ascii_code=ord($var[$i]);
229 if (intval($ascii_code) >=48 && intval($ascii_code) <=57)
230 return true;
231 else
232 continue;
233 }
234 return false;
235 }
236
237 print "done with this upload";
238 ?>
Something went wrong with that request. Please try again.