1. function Upload($uploaddir)
  2. {
  3. $tmp_name =$_FILES['file']['tmp_name']; // 文件上传后得临时文件名
  4. $name =$_FILES['file']['name']; // 被上传文件的名称
  5. $size =$_FILES['file']['size']; // 被上传文件的大小
  6. $type =$_FILES['file']['type']; // 被上传文件的类型
  7. $dir = $uploaddir.date("Ym");
  8. @chmod($dir,0777);//赋予权限
  9. @is_dir($dir) or mkdir($dir,0777);
  10. //chmod($dir,0777);//赋予权限
  11. move_uploaded_file($_FILES['file']['tmp_name'],$dir."/".$name);
  12. $type = explode(".",$name);
  13. $type = @$type[1];
  14. $date = date("YmdHis");
  15. $rename = @rename($dir."/".$name,$dir."/".$date.".".$type);
  16. if($rename)
  17. {
  18. return $dir."/".$date.".".$type;
  19. }
  20. }
  21. 调用:
  22. $image = Upload('../images/photo/');
复制代码


09-14 03:07