Ejemplo n.º 1
0
 /**
  * @Api
  */
 public function extract_keywords()
 {
     $this->load->helper('taxonomy');
     $s = $this->input->get('text');
     $output = json_encode(extractCommonWords($s));
     $this->output->set_output($output);
 }
 $encryptText = encryptData($text);
 //echo "<b>Encrypted Query : </b>".$encryptText;
 $query4 = mysql_query("select * from topkresults") or die(mysql_error());
 if (mysql_num_rows($query4)) {
     //table is not empty, delete data
     $query44 = mysql_query("truncate table topkresults");
 }
 $query7 = mysql_query("select * from topkencryptresults") or die(mysql_error());
 if (mysql_num_rows($query7)) {
     //table is not empty, delete data
     $query77 = mysql_query("truncate table topkencryptresults");
 }
 if (strlen($text) > 3) {
     $searchTimeTrustedStart = microtime(true);
     //break the query into keywords
     $words = extractCommonWords($text);
     //table is empty, insert data
     foreach ($words as $key => $value) {
         $query1 = mysql_query(" SELECT * FROM modifiedindex WHERE keyword like '%" . $key . "%' OR keyword like '" . $key . "%' OR keyword like '%" . $key . "' ") or die(mysql_error());
         //reterive data from normal index if particular keyword is present
         if (mysql_num_rows($query1)) {
             while ($rows = mysql_fetch_assoc($query1)) {
                 $id = $rows['file_id'];
                 $term = $rows['keyword'];
                 $freq = $rows['frequency'];
                 $term_freq = $rows['term_frequency'];
                 //if keyword is present, obtain the fileName from fileIndex using id reterived from normal index
                 if ($id) {
                     $query2 = mysql_query(" SELECT file_name FROM fileindex WHERE file_id = {$id} ") or die(mysql_error());
                     if (mysql_num_rows($query2)) {
                         $execute2 = mysql_fetch_array($query2);
 function uploadFile()
 {
     $uploadFileTimeStart = microtime(true);
     $target_dir = "C:\\xampp\\htdocs\\BEPROJECT\\Html\\Text/";
     $my_file = $_FILES["fileToUpload"]["name"];
     $target_file = $target_dir . basename($my_file);
     $FileType = pathinfo($target_file, PATHINFO_EXTENSION);
     try {
         // Undefined | Multiple Files | $_FILES Corruption Attack
         if (!isset($_FILES['fileToUpload']['error']) || is_array($_FILES['fileToUpload']['error'])) {
             throw new RuntimeException('<h2>Invalid parameters.</h2>');
         }
         // Check $_FILES['fileToUpload']['error'] value.
         switch ($_FILES['fileToUpload']['error']) {
             case UPLOAD_ERR_OK:
                 break;
             case UPLOAD_ERR_NO_FILE:
                 throw new RuntimeException('<h2>No file sent.</h2>');
             case UPLOAD_ERR_INI_SIZE:
             case UPLOAD_ERR_FORM_SIZE:
                 throw new RuntimeException('<h2>Exceeded filesize limit.</h2>');
             default:
                 throw new RuntimeException('<h2>Unknown errors.</h2>');
         }
         // Check if file already exists
         if (file_exists($target_file)) {
             throw new RuntimeException('<h2>File Already Exist in root directory.</h2>');
         }
         // Allow certain file formats
         if ($FileType != "txt") {
             throw new RuntimeException('<h2>Only Text files Allowed!</h2>');
         }
         //check filesize.
         if ($_FILES['fileToUpload']['size'] > 1000000) {
             throw new RuntimeException('<h2>Exceeded filesize limit.</h2>');
         }
         //obtain safe unique name from its binary data.
         if (!move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) {
             throw new RuntimeException('<h2>Failed to move uploaded file.</h2>');
         }
         echo '<h2>File is uploaded successfully.</h2>';
     } catch (RuntimeException $e) {
         echo $e->getMessage();
     }
     $uploadFileTimeEnd = microtime(true);
     $totalTimetoUploadFiles = $uploadFileTimeEnd - $uploadFileTimeStart;
     $_SESSION['uploadFile_time'] = $totalTimetoUploadFiles;
     $readFileContentsTimeStart = microtime(true);
     $handle = fopen("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Text/" . $my_file, "r") or die('Cannot open file: ' . $my_file);
     $filesize = filesize("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Text/" . $my_file);
     $contents = fread($handle, $filesize);
     $readFileContentsTimeEnd = microtime(true);
     $totalTimetoReadFiles = $readFileContentsTimeEnd - $readFileContentsTimeStart;
     $_SESSION['readTextFile_time'] = $totalTimetoReadFiles;
     $count_words = str_word_count($contents);
     //for calculating term frequency
     $words = extractCommonWords($contents, $filesize);
     //extracting keywords
     $id = getID($my_file, $filesize);
     //generating id
     toDatabase($id, $words, $count_words);
     //inserting to database
     display($my_file, $contents);
     //displaying final contents
 }
 function readContents($filename, $FileType)
 {
     $readFileContentsTimeStart = microtime(true);
     $var = $FileType;
     $myfile = $filename . "_" . $var . ".txt";
     //extracting contents of entire mumtimedia
     $actualName = $filename . "." . $FileType;
     $fullhandle = fopen("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Multimedia/" . $actualName, "r") or die("cannot create file!");
     $fullFilesize = filesize("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Multimedia/" . $actualName);
     $fullContents = fread($fullhandle, $fullFilesize);
     encryptData($fullContents, $actualName);
     //extracting contents of text enter while uploading MM
     $contents = $_POST['comment'];
     $handle = fopen("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Multimedia/" . $myfile, "w") or die("cannot create file!");
     fwrite($handle, $contents);
     $filesize = filesize("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Multimedia/" . $myfile);
     $readFileContentsTimeEnd = microtime(true);
     $totalTimetoReadFiles = $readFileContentsTimeEnd - $readFileContentsTimeStart;
     $_SESSION['readMMFile_time'] = $totalTimetoReadFiles;
     $count_words = str_word_count($contents);
     //for calculating term frequency
     $words = extractCommonWords($contents, $filesize);
     //extracting keywords
     $id = getID($myfile, $filesize);
     //generating id
     toDatabase($id, $words, $count_words);
     //inserting to database
     display($myfile, $contents, $filesize);
     //displaying final contents
 }