PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am using the upload script to below to upload an XML file. Before processing, I would like to check that the XML document is well formed by validating it against a XML schema.
<?php
if ($HTTP_POST_FILES['userfile']['name']=="none") {
echo "Problem: no file uploaded";
exit;
}
if ($HTTP_POST_FILES['userfile']['size']==0){
echo "Problem: uploaded file is zero length";
exit;
}
if ($HTTP_POST_FILES['userfile']['type'] != "text/xml") {
echo "Problem: file is not an xml file";
exit;
}
if (!is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "Problem: possible file upload attack";
exit;
}
$uploaddir = "uploads/";
$upfile = $uploaddir. $_FILES['userfile']['name'];
if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) {
echo "Problem: Could not move file into directory";
exit;
}
?>
I haven't done this myself, but from what I know, you do need SAX for that. There is tutorial here on SAX and PHP and a brief thread on validating XML with SAX here.