ユーザーがファイルをアップロードできるようにしようとしています。その内容は、SimpleXML を使用してデータベースに読み込まれます。私のコードは次のとおりです。
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');
}
}
}
(ユーザーを別のページにリダイレクトしてメッセージを表示する と のflash_message
定義がある MyBB を使用しています。)admin_redirect
私の問題は、まったくアップロードできないように見えることです。エラー メッセージは表示されません。さらに、ページが更新されるだけです。コンテンツのサンプルは次のとおりです。
<?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>
ファイル アップロード ボックスのid
andname
属性は「xml_file」です。私のローカルホストには PHP バージョン 5.3.13 もあります。