<?php

/**
 * @file generer_fichier_bidon.php
 * @brief Page qui génère un fichier de taille voulue.
 *
 * @author hughes monget
 * @see http://monget.com/
 */

set_time_limit(0);

$int_taille 1;
$str_aleas $str_collision '';
$str_extension 'txt';

define('INT_1_MEGA'1024 1024);

if (!empty(
$_REQUEST['taille']) && intval($_REQUEST['taille']) > 0)
{
    if (!empty(
$_REQUEST['aleas']))
    {
        
$str_aleas ' checked="checked" ';
    }
    if (!empty(
$_REQUEST['collision']))
    {
        
$str_collision ' checked="checked" ';
    }
    if (isset(
$_REQUEST['extension']) && is_string($_REQUEST['extension']) && ($str_tmp trim($_REQUEST['extension'])))
    {
        
$str_extension $str_tmp;
    }

    
$int_taille intval($_REQUEST['taille']);

    
$str_remplissage str_repeat(chr(0), INT_1_MEGA); // Remplissage de 0

    
if (!headers_sent())
    {
        
$str_anticollision '';
        if (
$str_collision)
        {
            
$str_anticollision '_'.md5(uniqid(mt_rand(), 1));
        }

        
header('Content-type: application/octet-stream');
        
header('Content-Disposition: attachment; filename="file_'.str_pad($int_taille3'0'STR_PAD_LEFT).'_mo'.$str_anticollision.'.'.$str_extension.'"');
        
header('Content-Transfer-Encoding: binary');
    }

    
ob_start();
    for (
$ii 0$ii $int_taille$ii++)
    {
        if (
$str_aleas)
        {
            
/*
            ob_start();
            for ($jj = 0; $jj < $int_iteration; $jj++)
            {
                echo chr(mt_rand() % 0x100);
            }
            $str_remplissage = ob_get_clean();
            */
            
$arr_aleas range(chr(0), chr(0xff));
            
shuffle($arr_aleas);
            
$str_seed md5(implode($arr_aleas), TRUE);
            
$int_iteration INT_1_MEGA strlen($str_seed);
            
ob_start();
            for (
$jj 0$jj $int_iteration$jj++)
            {
                echo (
$str_seed md5($str_seedTRUE));
            }
            
$str_remplissage ob_get_clean();
        }
        echo 
$str_remplissage;
    }
    
ob_end_flush();
    exit;
}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <title>Générer un fichier bidon (remplissage de 0 par défaut)</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <style type="text/css">
        </style>
    </head>
    <body>

        <form>
            <table>
                <tr>
                    <td><label for="taille">Taille en Mo</label></td>
                    <td><input type="text" id="taille" name="taille" value="<?php echo $int_taille ?>" maxlength="4" style="width:30px" /></td>
                </tr>
                <tr>
                    <td><label for="extension">Extension</label></td>
                    <td><input type="text" id="extension" name="extension" value="<?php echo $str_extension ?>" maxlength="4" style="width:30px" /></td>
                </tr>
                <tr>
                    <td><label for="aleas">Contenu aléatoire ?</label></td>
                    <td><input type="checkbox" id="aleas" name="aleas" <?php echo $str_aleas ?> /></td>
                </tr>
                <tr>
                    <td><label for="collision">Anti-collision ?</label></td>
                    <td><input type="checkbox" id="collision" name="collision" <?php echo $str_collision ?> /></td>
                </tr>
                <tr>
                    <td><input type="submit" value="générer" /></td>
                </tr>
            </table>
        </form>
<?php
echo '<hr />';
highlight_file(__FILE__);
?>

    </body>
</html>