Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php获取文件列表&;(与符号)字符错误_Php_File_List_Get_Character - Fatal编程技术网

php获取文件列表&;(与符号)字符错误

php获取文件列表&;(与符号)字符错误,php,file,list,get,character,Php,File,List,Get,Character,我有php中获取文件列表的代码,但如果文件名包含&字符,则不会显示该文件。 代码如下: 另外,我不是php程序员,我真的不知道这个错误是什么。 非常感谢您的帮助 非常感谢 <?php include_once('config.inc.php'); $current_dir = 'root'; if(array_key_exists('directory',$_POST)) { $current_dir = $_POST['directory']; } // Creating a new

我有php中获取文件列表的代码,但如果文件名包含&字符,则不会显示该文件。 代码如下:

另外,我不是php程序员,我真的不知道这个错误是什么。 非常感谢您的帮助 非常感谢

<?php
include_once('config.inc.php');
$current_dir = 'root';
if(array_key_exists('directory',$_POST)) {
$current_dir = $_POST['directory'];
}

// Creating a new XML using DOMDocument
 $file_list = new DOMDocument('1.0');
 $xml_root = $file_list->createElement('filelist');
 $xml_root = $file_list->appendChild($xml_root);

 // Setting the 'currentPath' attribute of the XML
 $current_path = $file_list->createAttribute('currentPath');
 $current_path->appendChild($file_list->createTextNode($current_dir));
 $xml_root->appendChild($current_path);

 // Replacing the word 'root' with the real root path
 $current_dir = substr_replace($current_dir, $root, 0, 4);

 $di = new DirectoryIterator($current_dir);

 // Creating the XML using DirectoryIterator
 while($di->valid())
 {
if(false == $di->isDot())
{
    if($di->isDir() && true != in_array($di->getBasename(),$h_folders))
    {
        $fl_node = $file_list->createElement('dir');
        $xml_root->appendChild($fl_node);
    }else if($di->isFile() && true !== in_array($di->getBasename(),$h_files) 
            &&  true !== in_array(get_ext($di->getBasename()),$h_types))
    {
        $fl_node = $file_list->createElement('file');
        $xml_root->appendChild($fl_node);
    }else 
    {
        $di->next();
            continue;
    }
    $name = $file_list->createElement('name',$di->getBasename());
    $fl_node->appendChild($name);
    $path = substr_replace($di->getRealPath(), 'root', 0, strlen($root));
    $path_node = $file_list->createElement('path', $path);
    $fl_node->appendChild($path_node);
    $di->next();
}else $di->next();
}

function get_ext($filename)
{
$exp = '/^(.+)\./';
return preg_replace($exp,'',$filename);
}

 // Returning the XML to Flash.
 echo $file_list->saveXML();
 ?>
createElement('filelist');
$xml\u root=$file\u list->appendChild($xml\u root);
//设置XML的“currentPath”属性
$current_path=$file_list->createAttribute('currentPath');
$current_path->appendChild($file_list->createTextNode($current_dir));
$xml\u root->appendChild($current\u path);
//用实际根路径替换单词“root”
$current\u dir=substr\u replace($current\u dir,$root,0,4);
$di=新的目录迭代器($current_dir);
//使用DirectoryIterator创建XML
而($di->valid())
{
if(false==$di->isDot())
{
如果($di->isDir()&&true!=在_数组($di->getBasename(),$h_文件夹))中
{
$fl_node=$file_list->createElement('dir');
$xml\u root->appendChild($fl\u节点);
}else如果($di->isFile()&&true!==在数组中($di->getBasename(),$h_文件)
&&true!==在数组中(获取外部($di->getBasename()),$h\u类型)
{
$fl_节点=$file_列表->createElement('file');
$xml\u root->appendChild($fl\u节点);
}否则
{
$di->next();
继续;
}
$name=$file_list->createElement('name',$di->getBasename());
$fl_node->appendChild($name);
$path=substr_replace($di->getRealPath(),'root',0,strlen($root));
$path\u node=$file\u list->createElement('path',$path);
$fl\u node->appendChild($path\u node);
$di->next();
}else$di->next();
}
函数get_ext($filename)
{
$exp='/^(+)\./';
返回preg_replace($exp,,$filename);
}
//将XML返回到Flash。
echo$file_list->saveXML();
?>

HTML中使用
&
字符来编写实体


如果您想在HTML中显示任意文本,需要调用
htmlentities()

对其进行转义,如果您提供了一些我可以帮助的源代码,文件内容而不是文件名。 如何获取文件列表的示例:

$c = "/some/path/to/file/here";
if(is_dir($c)){
foreach(scandir($c) as $file){
  if($file != '.' && $file != '..'){
    $d = $c.DIRECTORY_SEPARATOR.$file;
    echo " \"". realpath($d)  ."\"\n";
    }
}
}

你能在问题中加入你的代码吗?嗨,对不起,代码太长了,我不能发布它:(你可以编辑你的问题,最多包含大约30k的代码;你只需要在你的问题中加入相关的部分