Thomas (boggyb) wrote,

  • Mood:
  • Music:

Slightly improved file uploader

Anyway, enough ranting about nutters on the road. Remember the file uploader I hacked together earlier this year? Well, I discovered a slight flaw when using it with the Wii U - the filename provided by the console is static, and so later uploads overwrite earlier ones. That's easily fixed...

The change is only a few lines - the call to move_uploaded_file has been replaced with

      $pathinfo = pathinfo($_FILES['file']['name'][$i]);
      $dest = $pathinfo['filename'] . strftime('-%Y%m%d-%H%M%S.') . $pathinfo['extension'];
      move_uploaded_file($_FILES['file']['tmp_name'][$i], $dest);

The result is each uploaded file has the current date and time appended to it (for example, vorpal.jpeg becomes vorpal-20141120-205045.jpeg). Obviously this will still overwrite files if you manage to upload the same filename multiple times within the same second, to which my answer is meh! As before, feel free to use it under the 3-clause BSD license.
Tags: nas adventures, programming

  • Pancakes!

    Since people have been prodding me for an update, here's a pancake-themed one (as everyone's blogging about pancakes today!). Unlike in the linked…

  • Snap, crackle, pop (again)

    [Adam Savage voice] "Well there's your problem!" So while cooking supper the other day the oven went snap, crackle, and pop, and the magic smoke…

  • Of carpentry and networking

    So, I'm not sure if I've bought a wifi router or a Cylon Raider here... Work colleague: Cylon raider. So say we all. Housegroup friend: Or a…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.