Search code examples
joomla

PHP script to create index file


I need a php script that will create or copy from a path a blank index.html file for each folder that doesn't have one. If some one has one please share. Thanks H


Solution

  • Make your blank index.html - file and place it below your www- folder. Then, standing in the same place below your www- folder, try something like this:

    find www -type d -exec cp -n index.html {}/index.html \;
    

    ...where www is your www-folder. This should copy the index.html - file to all folders below the www-folder, including the www-folder itself. The copy -n flag ensures existing index.html - files are not overwritten.

    To make this into a php-script, you could just wrap it in a exec, like:

    <?php
    $path = 'path/to/www'; // www-folder
    $index = 'path/to/index.html';
    exec('find '.$path.' -type d -exec cp -n '.$index.' {}/index.html \;');
    

    Place the code above in a php-file.

    This solution is not platform independant, but will work on most flavours of *nix and mac.