Administrators Nathan Posted January 7, 2014 Administrators Posted January 7, 2014 How do I add a date and time to the end of my file upload?Currently I've tried: move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/".$orgid."/".$_FILES["file"]["name"].date("Y-m-d H:i:s")); This doesn't quite work as it appends like this: filename.jpg2014-01-06 12:01:05How can I do this so that it will be filename2014-01-06 12:01:05.jpg Quote
Administrators Nathan Posted January 8, 2014 Author Administrators Posted January 8, 2014 Found this as a fix: 1. You shouldn't use a colon in the filename. It's not compatible with every filesystem and can give you headaches later on. Also, if you can, avoid spaces, too. Use underscores and dashes to indicate those types of characters.2. Without the above corrections, here's what you're likely looking for, but I would highly recommend using my suggestions in #1: <?php // Split the original filename by the period character $pieces = explode(".",$_FILES["file"]["tmp_name"]); // Grab the last piece, which should be "jpg" $extension = array_pop($pieces); // Put the remaining pieces back together with the dot character, add the date, and then add a dot and the extension to get the new filename. $newfilename = implode(".",$pieces).date("Y-m-d H:i:s").".".$extension; // Move the file move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/".$orgid."/".$newfilename); ?> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.