PHP Combine files

From KOP KB
Revision as of 13:32, 21 May 2015 by ReMaster (talk | contribs) (Created page with "Combining A set of php files with the name of the files <syntaxhighlight lang="php"> <?php $files = array("a.php", "b.php", "c.php"); $comb; foreach ($files as $k) { $comb...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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