我用 PHP 制作了一个简单的 apk 上传器,我想解析清单属性表单AndroidManifest.xml
,但出现以下错误,有什么想法!?
Fatal error: Call to a member function xpath() on a non-object in E:\AppServ\www\apkUploader\mainApi.php on line 21
第 21 行 = $versionName = $xml->xpath('/manifest/@android:versionName');
源代码 :
/* For Apk File */
if (($_FILES["mFile"]["type"] == "application/vnd.android.package-archive") || ($_FILES["mFile"]["type"] == "application/octet-stream"))
{
if ($_FILES["mFile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["mFile"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["mFile"]["name"] . "<br />";
echo "Type: " . $_FILES["mFile"]["type"] . "<br />";
echo "Size: " . ($_FILES["mFile"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["mFile"]["tmp_name"] . "<br />";
error_reporting(E_ERROR | E_PARSE);
$dom = new DOMDocument();
$dom->load('AndroidManifest.xml');
$xml = simplexml_import_dom($dom);
$versionName = $xml->xpath('/manifest/@android:versionName');
$versionCode =$xml->xpath('/manifest/@android:versionCode');
$package = $xml->xpath('/manifest/@package');
echo "VERSION NAME :".$versionName[0]->versionName."<br/>";
echo "VERSION CODE :".$versionCode[0]->versionCode."<br/>";
echo "VERSION PAC :".$package[0]->package."<br/>";
if (file_exists("upload/" . $_FILES["mFile"]["name"]))
{
echo $_FILES["mFile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["mFile"]["tmp_name"],
"upload/" . $_FILES["mFile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["mFile"]["name"];
}
}
}
else
{
echo "Invalid file";
}