Skip to content

Instantly share code, notes, and snippets.

@houhr
Last active December 25, 2015 16:09
Show Gist options
  • Save houhr/7003862 to your computer and use it in GitHub Desktop.
Save houhr/7003862 to your computer and use it in GitHub Desktop.
<?php
/**
* 利用上传文件时间生成唯一ID,用于解决用户一次选择多个文件时,文件名相同的问题
* @return int Unix时间戳小数点右移四位取整
*/
function upload_time() {
list($msec, $sec) = explode(" ", microtime());
return ((int)$sec . (int)($msec * 10000));
}
if (!empty($_FILES['file']['name'])) {
$file = $_FILES['file'];
move_uploaded_file($file['tmp_name'], upload_time() . $file['name']);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment