啥也不说了,看代码 <?php /***************************************************** 程序名称: PHP文件上传测试 程序说明: 编写时间: 2011年4月23日 编写人员: 童童 修改时间: 2011年4月23日 修改人员: 童童 备 注: ****************************************************/ /**************************************** 函数名称: GetGUID 函数内参: 函数功能: 获取GUID 编写时间: 2011年4月23日 编写人员: 童童 修改时间: 2011年4月23日 修改人员: 童童 备 注: ****************************************/ function GetGUID() { if (function_exists('com_create_guid')) { return com_create_guid(); } else { mt_srand((double)microtime()*10000); $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45);// "-" $uuid = chr(123)// "{" .substr($charid, 0, 8).$hyphen .substr($charid, 8, 4).$hyphen .substr($charid,12, 4).$hyphen .substr($charid,16, 4).$hyphen .substr($charid,20,12) .chr(125);// "}" return $uuid; } } /**************************************** 函数名称: MakeUploadNewFileName 函数内参: $type 生成新文件名类型(1-年月日时分秒+6位随机数 / 2-GUID) 函数功能: 生成新文件名 编写时间: 2011年4月23日 编写人员: 童童 修改时间: 2011年4月23日 修改人员: 童童 备 注: 文件生成算法: 当每日上传量在6位数时,考虑用1 当每日上传量大于6位数,考虑用2 ****************************************/ function MakeUploadNewFileName($type) { $value = ""; switch ($type) { case 0: echo "a"; break; case 1: $value = date("YmdHis") . mt_rand(10000,100000); break; case 2: $value = GetGUID(); break; } return $value; } echo '单个上传文件大小限制:'.ini_get('upload_max_filesize') ; echo "<br/>"; echo '上传文件总大小限制:'.ini_get('post_max_size') ; echo "<br/>"; if($_SERVER['REQUEST_METHOD']=='POST') { $file_path = 'd://web//php//test//'; $newfilename = MakeUploadNewFileName(2); $allowedExtensions = array("txt","csv","htm","html","xml","css","doc","xls","rtf","ppt","pdf","swf","flv","avi","wmv","mov","jpg","jpeg","gif","png"); foreach ($_FILES as $file) { if ($file['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { die($file['name'].' 为非法文件类型!<br/>'. '<a href="javascript:history.go(-1);" mce_href="javascript:history.go(-1);">'. '<< 返回</a>'); } else { //添加文件名 $newfilename .= '.'.end(explode(".", strtolower($file['name']))); } } } try { move_uploaded_file($_FILES['file1']['tmp_name'], $file_path . $newfilename); echo "<p>文件上传成功!</p>"; echo "<br/>"; echo '上传文件名:'.$_FILES['file1']['name']."<br/>"; echo '上传文件类型:'.$_FILES['file1']['type']."<br/>"; echo '上传文件大小:'.$_FILES['file1']['size'].' 字节'."<br/>"; echo '上传文件临时文件名:'.$_FILES['file1']['tmp_name']."<br/>"; echo '上传文件失败的错误代码:'.$_FILES['file1']['error']."<br/>"; } catch (Exception $e) { echo "文件上传失败!错误代码:".$_FILES['file1']['error']."<br/>"; echo $e; } } ?> <p>请上传文件:</p> <form enctype="multipart/form-data" id="form_upload" method="post" action="test5.php"> <input id="file1" name="file1" type="file" value="" /> <input type="submit" id="submit" value="提交" /> <input type="reset" id="reset" value="重置" /> </form>