我正在尝试输入复选框列表当前文件夹.mp3获取使用gob函数glob_grace列出音频文件使用复选框然后复选框
获取数组复选框值使xspf文件使用php
我将数组代码全部写入xml。
但是小的错误,请任何人告诉我什么错误和哪里发生的错误!
<?php
foreach (glob("*.{mp3,mp4}", GLOB_BRACE) as $filename) {
$values = $filename ;
echo "<form action='p.php' method='POST'>";
echo "<input type='checkbox' name='foo[]' value='$values'>$values <hr>";
}
echo "<input type='submit' name='submit' value='Submit'>";
echo "</form>";
?>它将转到下一页
<?php
$g = $_POST['foo'];
$cnt = count($g);
//function definition to convert array to xml
function array_to_xml($array, &$xml_user_info) {
for ($i=0 ; $i < $cnt ;$i++)
{
$track = $xml_user_info->addChild('track');
$track->addChild("location",$array[$i]);
}
}
//creating object of SimpleXMLElement
$xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><trackList></trackList>");
//function call to convert array to xml
array_to_xml($g,$xml_user_info);
//saving generated xml file
$xml_file = $xml_user_info->asXML('users.xspf');
//success and error message based on xml creation
if($xml_file){
echo 'XML file have been generated successfully.';
}else{
echo 'XML file generation error.';
}
?>请给我答案解决方案工作代码
提前感谢
发布于 2015-12-17 16:53:22
如果glob("*.{mp3,mp4}", GLOB_BRACE)返回一个具有多个项的数组,则需要多次生成<form action='p.php' method='POST'>标记。
也许您可以将表单声明移到foreach之外。
如果我提交了表单并加载了p.php,我会收到以下通知:
注意:未定义变量: cnt
您正在使用$cnt = count($g);对项目进行计数,但也可以传递此$g并在function array_to_xml中计数其项。
我认为,如果您想从$_POST['foo']中获得值,首先应该检查它是否是POST,然后检查是否设置了$_POST['foo']。
也许这个设置可以帮助您:
<?php
//function definition to convert array to xml
function array_to_xml($array, &$xml_user_info)
{
for ($i = 0; $i < count($array); $i++) {
$track = $xml_user_info->addChild('track');
$track->addChild("location", $array[$i]);
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['foo'])) {
$g = $_POST['foo'];
//creating object of SimpleXMLElement
$xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><trackList></trackList>");
//function call to convert array to xml
array_to_xml($g, $xml_user_info);
//saving generated xml file
$xml_file = $xml_user_info->asXML('users.xspf');
//success and error message based on xml creation
if ($xml_file) {
echo 'XML file have been generated successfully.';
} else {
echo 'XML file generation error.';
}
}
}
?>发布于 2020-06-15 23:47:43
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><playlist></playlist>');
$trackList = $xml->addChild('trackList');
foreach ($_POST['files'] as $video) {
$track = $trackList->addChild('track');
$track->addChild('location', 'file://'.$tmp_dir.'/'.$video['path']);
$track->addChild('title', $video['name']);
}
file_put_contents('playlist.xspf',$xml->asXML());https://stackoverflow.com/questions/34335067
复制相似问题