Attempting to upload an xml file and parse
#1
I'm trying to upload and parse an XML file to the server, which is generated by my wiki plugin and offered as a download. Problem - absolutely nothing is happening. Angry

This is the contents of my import.php file:

<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$lang->load('wiki');

$page->add_breadcrumb_item($lang->wiki_import, 'index.php?module=wiki-import');

$page->output_header($lang->wiki_import);

$sub_tabs['wiki_import'] = array(
	'title'			=> $lang->wiki_import,
	'link'			=> 'index.php?module=wiki-import',
	'description'	=> $lang->wiki_import_description
);

$page->output_nav_tabs($sub_tabs, 'wiki_import');

if($mybb->request_method != 'POST')
{
	$form = new Form('', 'POST', '', 1, '', false, '');
	$form_container = new FormContainer($lang->wiki_import);
	$form_container->output_row($lang->wiki_xml_file, $lang->wiki_xml_file_desc, $form->generate_file_upload_box('xml_file', "", array('id' => 'xml_file')));
	$form_container->end();
	$buttons = array();
	$buttons[] = $form->generate_submit_button($lang->wiki_commit);
	$form->output_submit_wrapper($buttons);
	$form->end();
}
else
{
	$info = pathinfo($_FILES['xml_file']['tmp_name']);
	$extension = $info['extension'];

	if($extension != 'xml')
	{
		flash_message($lang->wiki_invalid_file, 'error');
		admin_redirect('index.php?module=wiki-import');
	}
	else
	{
		$string = file_get_contents($_FILES['xml_file']['tmp_name']);
		$xml = new SimpleXMLElement($string);
		foreach($xml->wiki->article as $article)
		{
			$query = "INSERT INTO " . TABLE_PREFIX . "wiki('authors','title','content','protected','lastauthor','lastauthorid','category') VALUES('" . $article->authors . "','" . $article->title . "','" . $article->content . "','" . $article->protected . "','" . $article->lastauthor . "','" . $article->lastauthorid . "','" . $article->category . "',)";
			$db->write_query($query);
			if($db->error_number > 0)
			{
				flash_message($lang->wiki_import_error, 'error');
				admin_redirect('index.php?module=wiki-import');
			}
			else
			{
				flash_message($lang->wiki_import_success, 'success');
				admin_redirect('index.php?module=wiki-import');
			}
		}
	}
}

$page->output_footer();

?>

Absolutely nothing happens, no error messages, nothing. The file is not inserted into the db. What am I doing wrong? Smile
Please don't PM me for support. Smile
Reply
#2
Have you activated the plugin? I suggest doing it after you've completely installed the files into the server. Also, adjust the settings after activating the plugin.
Reply
#3
Yes, it's all installed and activated. There are no settings (yet) related to the importing of articles.

This is a sample output from the export:

<?xml version="1.0" ?>
<wiki>
	<article>
		<id>1</id>
		<title>To be Exported</title>
		<content>
			Export me!
		</content>
		<category>Meta</category>
		<lastauthor>admin</lastauthor>
		<lastauthorid>1</lastauthorid>
		<protected>0</protected>
		<authors>1</authors>
	</article>
</wiki>

I'm also on localhost, if that changes anything?
Please don't PM me for support. Smile
Reply
#4
Bump.
Please don't PM me for support. Smile
Reply
#5
This user has been denied support. This user has been denied support.
Which PHP version are you using, maybe it's lacking SimpleXML.
Reply
#6
I'm using 5.3.13 - and I think SimpleXML came with PHP5?
Please don't PM me for support. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)