I am attempting to allow users to upload a file, the contents of which would then be read into a database using SimpleXML. My code is as follows:
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
{
if($_FILES['xml_file']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['xml_file']['tmp_name']))
{
$string = file_get_contents($_FILES['xml_file']['tmp_name']);
$xml = new SimpleXMLElement($string);
foreach($xml->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 . "',)";
$sql = $db->write_query($query);
if($db->error_number() > 0)
{
flash_message($lang->wiki_import_error, 'error');
admin_redirect('index.php?module=wiki-import');
}
elseif(!$sql)
{
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');
}
}
}
else
{
flash_message($lang->wiki_import_error, 'error');
admin_redirect('index.php?module=wiki-import');
}
}
}
(I am using MyBB, which has definitions for flash_message
and admin_redirect
, which redirects the user to another page and displays a message.)
My issue is that I cannot seem to upload it at all, no error message is shown. In addition, the page just refreshes. A sample piece of content is:
<?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>
The id
and name
attribute of the file upload box is 'xml_file'. I also have PHP version 5.3.13 on my localhost.