PHP Combine files

From KOP KB
Jump to: navigation, search

Combining A set of php files with the name of the files

<?php
$files = array("a.php", "b.php", "c.php");
$comb;
foreach ($files as $k)
{
    $comb .= file_get_contents("./".$k);
}
file_put_contents("./combined.php",$comb);
?>

If you are grabbing it from a form submission you can try this.

<?php
$files = array();
foreach ($_POST['files_to_combine'] as $k)
{
    $files .= $k;
}
$comb;
foreach ($files as $k)
{
    $comb .= file_get_contents("./".$k);
}
file_put_contents("./combined.php",$comb);
?>

NOTE: Don't forget Little Bobby Tables: http://www.xkcd.com/327/

Source: http://stackoverflow.com/questions/25433555/combining-multiple-php-files/25434613#25434613