php - Micro timestamp and/or random string to file name -
so part of upload file setting name of file struggling append time stamp onto file name or set random string or both?
here setting file name , type:
if ( move_uploaded_file($_files['upload']['tmp_name'], "../uploads/{$_files['upload']['name']}")){ print_r($_files); echo '<p><em>the file has been uploaded</em></p>'; } // end of move.... if.
adding timestamp idea. do:
$date = new datetime(); if (move_uploaded_file($_files['upload']['tmp_name'], "../uploads/" . $date->gettimestamp() . "_{$_files['upload']['name']}")){ print_r($_files); echo '<p><em>the file has been uploaded</em></p>'; }
note have added underscore _
after timestamp becomes easier remove timestamp if need initial filename again:
substr($filename, strpos($filename, '_'), strlen($filename));
Comments
Post a Comment