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";
}