Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 19ef3b3220
Fetching contributors…

Cannot retrieve contributors at this time

238 lines (230 sloc) 6.884 kB
<?
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL); ini_set('display_errors', 1);
ignore_user_abort(false);
$ep = "../Global/";
include "../Global/MySQL.php";
$h = fopen("./up.txt",'w');
//fwrite($h,"-------- REQUEST FILES-----------------------------------------\n");
//fwrite($h,"\n".print_r($_FILES,true));
//fwrite($h,"-------- REQUEST -----------------------------------------\n");
//fwrite($h,"\n".print_r($_REQUEST,true));
//fwrite($h,"-----------------------------------------------------\n");
print "<pre>";
print_r($_REQUEST);
print "</pre>";
$sk = $_REQUEST["sk"];
if($_REQUEST["Set"]=="head" || $_REQUEST["Set"]=="foot")
{
$ObjID = $_REQUEST["NID"];
$ObjType = "NID";
$Role = 8; //Modify Data Node
$Auth = AuthForObject($sk,$ObjType,$ObjID,$Role);
if(!$Auth)
{
print "Access Denied";
//fwrite($h,"\nAccess Denied:\n");
//fwrite($h,"\nUsr:".$_REQUEST["Usr"]);
//fwrite($h,"\nPass:".$_REQUEST["Pass"]);
//fwrite($h,"\nObjType:".$ObjType);
//fwrite($h,"\nObjID:".$ObjID);
//fwrite($h,"\nRole:".$Role);
exit();
}
}
else
{
$ObjID = $_REQUEST["RID"];
$ObjType = "RID";
}
$Role = 11; //Add Files
$Auth = AuthForObject($sk,$ObjType,$ObjID,$Role);
if(!$Auth)
{
print "Access Denied";
//fwrite($h,"\nAccess Denied");
exit();
}
//print "r=".rand(0,1000);
$PathArray = array();
$NID = $_REQUEST["NID"];
if($_REQUEST["Set"]=="head" || $_REQUEST["Set"]=="foot")
$path = $__HeadFootServerPath;
else
$path = GetPathForNode($NID,$PathArray)."/";
foreach($_FILES as $key=>$val)
{
$date = date("Y-m-d");
/////// UNIQUE NAME ///////
$NewName = ereg_replace("[ ()]","",$_FILES[$key]['name']);
$NewName = strtolower($NewName);
if(file_exists($path.$_REQUEST["RID"]."_".$date."_".$NewName))
{
$count = 1;
while((file_exists($path.$date."_".$count."_".$NewName)))
$count++;
$FileName = $_REQUEST["RID"]."_".$date."_".$count."_".$NewName;
}
else
$FileName = $_REQUEST["RID"]."_".$date."_".$NewName;
////////////////////////////
//fwrite($h,"\nTrying to Move File to:".$path.$FileName);
if (move_uploaded_file($_FILES[$key]['tmp_name'], $path.$FileName))
{
//fwrite($h,file_exists($path.$FileName)?"yes it exists":"no this sucks...");
//fwrite($h,"\nMoved File:".$path.$FileName);
if($_REQUEST["Set"]=="head")
{
SetHeaderImg($NID,$FileName);
}
else if($_REQUEST["Set"]=="foot")
{
SetFooterImg($NID,$FileName);
}
else if($_REQUEST["Set"]=="REC")
{
$Size = filesize($path.$FileName);
$FileTypeA = explode(".", $FileName);
$FileType = $FileTypeA[1];
if(empty($_REQUEST["OCR"]) || $_REQUEST["OCR"]=="TRUE")
{
$CMD = "tesseract ".$path.$FileName." ".$path.$FileName." -l spa";
$output = array();
$result = exec(escapeshellcmd($CMD),$output);
//fwrite($h,"\nCMD:".$CMD);
//fwrite($h,"\noutput:".print_r($output,true));
//fwrite($h,"\nResult:".$result);
$pspellDictionary = pspell_new("en",'american','','',PSPELL_FAST);
//fwrite($h,"\npspell_link:".$pspellDictionary);
if(file_exists($path.$FileName.".txt"))
$lines = file($path.$FileName.".txt");
else
$lines = file($path.$FileName);
//fwrite($h,"\nExtracted Lines");
$extractedWords = "";
$NewWord = "";
foreach ($lines as $line_num => $line)
{
for($i=0; $i<strlen($line); $i++)
{
$c = $line[$i];
$o= ord(strtolower($c));
if( (($o>=97)&&($o<=122)) || (($o>=48)&&($o<=57)) || ($o==45)) //a to z || 0 to 9
$NewWord .=$c;
else if($o!=0)
{
if(is_numeric($NewWord))
{
$extractedWords.= $NewWord." ";
}
else if(strlen($NewWord)>3)
{
if(!stristr($extractedWords,$NewWord))
{
$ValidWord=true;
//fwrite($h,"\nlooking at word:".$NewWord);
if(HasNum($NewWord))
{
//fwrite($h," <=== Word is a mix");
}
else if(pspell_check($pspellDictionary, $NewWord))
{
//fwrite($h," <=== Word is spelled correctly");
$extractedWords.= $NewWord." ";
}
else
{
//fwrite($h," <=== Word is miss spelled");
$TempWord = "";
$BestMatch = 3;
$Suggestions = pspell_suggest($pspellDictionary,$NewWord);
//fwrite($h,"\nSugested words:\n");
foreach($Suggestions as $k=>$suggested)
{
$src = btlfsa($NewWord,$suggested);
//fwrite($h,"\t".$suggested.":".$src."\n");
if($BestMatch<$src)
{
$BestMatch = $src;
$TempWord = $suggested;
}
}
if(!empty($TempWord))
$extractedWords.= $TempWord." ";
//else
// $extractedWords.= $NewWord." ";
}
}
}
$NewWord = "";
}
}
}
unlink($path.$FileName.".txt");
//fwrite($h,"\nProcesed Lines");
}
$md5 = md5_file($path.$FileName);
try
{
//fwrite($h,"\ninserting words:".$extractedWords."\n");
//fwrite($h,"\nInserting Lines");
$ins = InsertFileToRecord($_REQUEST["NID"],$_REQUEST["RID"],$_FILES[$key]['name'],$FileName,$path,$Size,$FileType,$_REQUEST["Usr"],esc($extractedWords),$md5,$_REQUEST["RID"]);
//fwrite($h,"\nInsert:".$ins);
}
catch(Exception $e)
{
unlink($path.$FileName);
//fwrite($h,"\nError:".$e->getMessage());
}
//$path.$FileName
}
}
else
fwrite($h,"\nFailed to move File:".$NewName);
}
function btlfsa($word1,$word2)
{
$score = 0;
// For each char that is different add 2 to the score
// as this is a BIG difference
$remainder = preg_replace("/[".preg_replace("/[^A-Za-z0-9\']/",' ',$word1)."]/i",'',$word2);
$remainder .= preg_replace("/[".preg_replace("/[^A-Za-z0-9\']/",' ',$word2)."]/i",'',$word1);
$score = strlen($remainder)*2;
// Take the difference in string length and add it to the score
$w1_len = strlen($word1);
$w2_len = strlen($word2);
$score += $w1_len > $w2_len ? $w1_len - $w2_len : $w2_len - $w1_len;
// Calculate how many letters are in different locations
// And add it to the score i.e.
//
// h e a r t
// 1 2 3 4 5
//
// h a e r t a e = 2
// 1 2 3 4 5 1 2 3 4 5
//
$w1 = $w1_len > $w2_len ? $word1 : $word2;
$w2 = $w1_len > $w2_len ? $word2 : $word1;
for($i=0; $i < strlen($w1); $i++)
{
if ( !isset($w2[$i]) || $w1[$i] != $w2[$i] )
{
$score++;
}
}
return $score;
}
function HasNum($var)
{
for ($i=0;$i<strlen($var);$i++)
{
$ascii_code=ord($var[$i]);
if (intval($ascii_code) >=48 && intval($ascii_code) <=57)
return true;
else
continue;
}
return false;
}
print "done with this upload";
?>
Jump to Line
Something went wrong with that request. Please try again.