Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By newtoid on
I have made a view which outputs an xml file using views (obviously) and views_data_export
I need to convert each node in the xml to an html file with the node title as the file title, then create a folder, dump all the files there, tar them up, then force a download.
I can make this happen on my installation of mamp, using the following code.
/**
* @file
* actorconverter.php
* Converts xml feed of actor data to html files
*/
//errors on
error_reporting(E_ALL);
ini_set('display_errors', '1');
//load xml file
$xml = simplexml_load_file('actorexport.xml');
//print the bits we want
foreach ($xml->node as $node)
{ $filestring = "<html>\r\n";
$filestring .="<body>\r\n";
$filestring .= $node->title;
$filestring .= $node->description;
$filestring .= $node->reports;
$filestring .= $node->contact;
$filestring .="</body>";
$filestring .="</html>";
//create today's output directory if it doesnt exist
if (!is_dir('actors'.date('mdY')))
{
mkdir('actors'. date('mdY'));
}
$outputdir=('actors'. date('mdY'));
//write string to file
$htmlfile = fopen(str_replace(" ", "\x20", strip_tags($outputdir .'/' .$node->title.'.html')), "w+");
fwrite($htmlfile, $filestring);
fclose($htmlfile);
};
//archive files
shell_exec('tar -cvzf ' .$outputdir.'.tar '.$outputdir.'/*.html');
//force download
$download = ($outputdir.'.tar');
if (file_exists($download))
{
header("Content-disposition: attachment; filename=" .$download);
header("Content-type: application/tar");
readfile($download);
exit;
};
However I can't make it work on the remote site, I have tried for days to figure it out. ANY suggestions welcomed greatly!