示例#1
0
function do_handle_upload()
{
    if ($_FILES['data_file']['error'] === UPLOAD_ERR_OK) {
        $file_name = $_FILES['data_file']['name'];
        $extension = pathinfo($file_name);
        if (!isset($extension['extension'])) {
            $extension = '';
        } else {
            $extension = strtolower($extension['extension']);
        }
        if ($extension != 'aiml') {
            print '<p>Invalid file format.</p>';
        } else {
            $in_dest = JxBotConfig::aiml_dir() . $file_name;
            if (!@move_uploaded_file($_FILES['data_file']['tmp_name'], $in_dest)) {
                print '<p>Couldn\'t save file. Check the permissions on the aiml directory.</p>';
            } else {
                //print '<p>File uploaded successfully.</p>';
                JxBotNLData::set_file_status($file_name, 'Not Loaded');
            }
        }
    } else {
        print '<p>Error uploading file.</p>';
    }
}
示例#2
0
文件: aiml.php 项目: jhawcroft/jxbot
 public function import($in_filename)
 {
     /* reset the importer */
     $this->reset();
     /* open the file */
     $fh = fopen($in_filename, 'r');
     if (!$fh) {
         return "Server Error: Couldn't open AIML file.";
     }
     /* parse the file */
     $size = filesize($in_filename);
     $bytes = 0;
     while ($data = fread($fh, 4096)) {
         if (!xml_parse($this->xml_parser, $data, feof($fh))) {
             $this->error(xml_error_string(xml_get_error_code($this->xml_parser)));
             break;
         }
         $bytes += 4096;
         if ($bytes > $size) {
             $bytes = $size;
         }
         $percent = number_format($bytes / $size * 100, 1);
         JxBotNLData::set_file_status(basename($in_filename), 'Loading ' . $percent . '%');
     }
     xml_parse($this->xml_parser, '', true);
     fclose($fh);
     /* report errors */
     if ($this->_error != '') {
         return $this->_error;
     }
     /* prepare additional notices */
     if (count($this->unrecognised) > 0) {
         $this->notice('The following unrecognised tags were ignored: ' . implode(', ', array_keys($this->unrecognised)), true);
     }
     if ($this->has_aiml1_learn) {
         $this->notice('This AIML file expects the AIML 1.0 semantics of the learn tag, which are not supported by JxBot.', true);
     }
     if ($this->has_aiml1_gossip) {
         $this->notice('This AIML file utilises the old AIML 1.0 gossip tag, which is not supported by JxBot.', true);
     }
     if ($this->has_aiml2_learn) {
         $this->notice('This AIML file utilises the AIML 2.0 learn feature which is not yet supported by JxBot.', true);
     }
     if ($this->has_aiml2_sraix) {
         $this->notice('This AIML file utilises the AIML 2.0 sraix feature which is not yet supported by JxBot.', true);
     }
     if ($this->has_aiml2_loop) {
         $this->notice('This AIML file utilises the AIML 2.0 loop feature which is not yet supported by JxBot.', true);
     }
     if ($this->has_aiml2_interval) {
         $this->notice('This AIML file utilises the AIML 2.0 interval tag which is not yet supported by JxBot.', true);
     }
     if ($this->has_aiml_javascript) {
         $this->notice('This AIML file utilises the AIML server-side javascript feature, which is not supported by JxBot.', true);
     }
     if ($this->has_aiml_system) {
         $this->notice('This AIML file utilises the AIML system call feature, which is not yet supported by JxBot.', true);
     }
     if ($this->has_multi_pattern_cats) {
         $this->notice('This AIML file utilises the JxBot consolidated category representation, which may not be compatible with other AIML interpreters.', true);
     }
     if ($this->has_tag) {
         $this->notice('This AIML file utilises the JxBot tag feature, which may not be compatible with other AIML interpreters.', true);
     }
     /* return the result */
     return $this->notices;
 }