Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (4)

Powered by Vanilla. Made with Bootstrap.
Filename "generator"
  • From Poison, my Filename "generator".

    So i had about 3,000 + images from holidays, partys, random times etc etc, and i noticed that sometimes that i had conflicts with the file names being two of the same, so instead of relying on the camera putting a random file name which for some reason didn't work Huh, i decided to go through my images today, and create a "random file name generator".

    Basically what it does is generate random numbers, this itself is reasonably unique as it starts from 1000 to 9999999999; but numbers aren't exactly unique enough i thought, SO i decided to md5 the output thus saving me the bother of implementing letters to the number.

    It may or may not have practical use in "real life" but it does serve a tutorial purpose at least. I do plan however to implement a renaming feature, so it renames files with the output but we'll see.

    Filename Generator UPDATE
    Changes:
    added output to file.
    Added session so it'd save filename according to your session number (incase on web servers etc rather than localhost).
    Outputs into textarea.



    <?php
    //Note: this is NOT 100% unique. It's reasonably unique.
    //Whilst creating 100,000 random numbers, i got 4 duplicates.

    //For unique file names
    session_start();
    if(!isset($_SESSION['rng'])) //RandomNumberGenerator
    {
    $_SESSION['rng'] = rand(100,9999999999);
    }
    //It will be used like this $fn = $_SESSION['rng'].\".txt\";
    //End
    if(isset($_GET['ds'])) //Destroy session
    {
    session_destroy();
    }
    echo \"Your temp ID: \". $_SESSION['rng'];
    echo '<center>';
    $random_number = rand(100,9999999999);
    $counter = 0;
    echo '<form action=\"counter.php?save\" method=\"post\">';
    echo '<textarea rows=20 cols=100 name=\"output\" style=\"text-align:center;\">';
    while($counter !=50 && $random_number !=9999999999)
    {
    $random_number = md5($random_number);
    //echo \"Counter: \".$counter.\" \";
    echo $random_number.\"\n\"; //\"Random number: \".
    $counter ++;
    $random_number = rand(100,9999999999);
    }
    echo '</textarea><br/>';
    echo '<input type=\"submit\" value=\"Save\"/></form>';
    echo '<br/><a href=\"counter.php\">Refresh</a>';
    echo '<br/>';
    if(isset($_GET['save']))
    {
    //Be careful when using large counter because POST size has limits.
    //So if you want to use large counter, save manually.
    $fn = $_SESSION['rng'].\".txt\";
    $fh = fopen($fn,'w');
    $data = $_POST['output'].\"\n\";
    fwrite($fh,$data);
    fclose($fh);
    echo '<br/>Saved successfully! <small>To update the file, click save again.</small></center>';
    }
    ?>