Good day every one
I have a problem. I have a folder in my webroot/files that has some documents in it, mainly doc files. I want to read all the contents of the files. e.g. if there are 2 files, namely users.docx and funds.docx. I want to be able to open each file, read its content, and write them to a single document.
so far the code i have writes only the 1st file, but the newly written file has a size of both the read files.
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 .= "
";
echo($h."
");
}
file_put_contents($my_file, $data);
fclose($handle);
}
A docx file is actually a directory so you will need to open that if you want to actually get to the xml that makes up the file. However, the contents of the directory is pretty complex and consists of many different files.
It's very unlikely that you will be able to find the right parts of each file and combine them together to make a valid file afterwards with a script.