Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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_Cakephp - Fatal编程技术网

读取php目录中的所有文件

读取php目录中的所有文件,php,cakephp,Php,Cakephp,大家好 我有个问题。 我的webroot/files中有一个文件夹,其中包含一些文档,主要是文档文件。 我想读取文件的所有内容。e、 g.如果有2个文件,即users.docx和funds.docx。 我希望能够打开每个文件,读取其内容,并将其写入单个文档 到目前为止,我的代码只写了第一个文件,但新写的文件的大小与读文件的大小相同 function writeToFile($insId,$path,$hospital){ $data = ''; $my_file

大家好

我有个问题。 我的webroot/files中有一个文件夹,其中包含一些文档,主要是文档文件。 我想读取文件的所有内容。e、 g.如果有2个文件,即users.docx和funds.docx。 我希望能够打开每个文件,读取其内容,并将其写入单个文档

到目前为止,我的代码只写了第一个文件,但新写的文件的大小与读文件的大小相同

function writeToFile($insId,$path,$hospital){
         $data = '';
        $my_file  =  WWW_ROOT . 'files' . DS . 'instructions' . DS . $insId . DS ."Final Report ".$insId.".rtf";

                            $handle = fopen($my_file, 'w')or die('Cannot open file:  '.$my_file); //implicitly creates file
                            foreach($hospital as $h){
                            $data .= file_get_contents($path.'/'.$h, false);
                            $data .= "\n";
                            echo($h."\n");
                            }
                            file_put_contents($my_file, $data);
                           fclose($handle);
     }

docx文件实际上是一个目录,因此如果您想要实际访问构成该文件的xml,则需要打开该目录。但是,目录的内容相当复杂,由许多不同的文件组成


您不太可能找到每个文件的正确部分,然后将它们组合在一起,然后使用脚本生成一个有效的文件

你认为连接两个Word文档的内容会得到一个有效的文件吗?我不知道docx格式,但我假设它是二进制的,或者至少是某种XML结构。恐怕您要做的工作要比简单的读/写工作多得多。请看一下docx是zip压缩的xml文件。您不能仅仅将原始二进制文件连接在一起并期望它工作。