PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/deal/change-msg.php

https://gitlab.com/yawenzou/thing_street
PHP | 86 lines | 76 code | 3 blank | 7 comment | 7 complexity | 5b955b8603cea1bd595ab18f6ef6cbb1 MD5 | raw file
  1. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  2. <?php
  3. //我是基本信息完善页面
  4. require("dbconfig.php");
  5. session_start();
  6. $nicknames=$_SESSION['name'];
  7. $name=$_POST['name'];
  8. $cellphone=$_POST['cellphone'];
  9. $birthday=$_POST['birthday'];
  10. $professional=$_POST['professional'];
  11. $sex=$_POST['sex'];
  12. $seltuser=mysql_query("select * from user where nicknames='$nicknames'")or die(mysql_error());
  13. $user_id=mysql_fetch_assoc($seltuser);
  14. $user_id_data=$user_id['id'];
  15. $uploaddir = "../user_photo/";//设置文件保存目录 注意包含/
  16. $type=array("jpg","gif","bmp","jpeg","png");//设置允许上传文件的类型
  17. //获取文件后缀名函数
  18. function fileext($filename)
  19. {
  20. return substr(strrchr($filename, '.'), 1);
  21. }
  22. //生成随机文件名函数
  23. function random($length)
  24. {
  25. $hash = 'CR-';
  26. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  27. $max = strlen($chars) - 1;
  28. mt_srand((double)microtime() * 1000000);
  29. for($i = 0; $i < $length; $i++)
  30. {
  31. $hash .= $chars[mt_rand(0, $max)];
  32. }
  33. return $hash;
  34. }
  35. $a=strtolower(fileext($_FILES['avatar']['name']));
  36. if(!$a){
  37. //$echo_massage = "请上传头像";
  38. }
  39. else{
  40. //判断文件类型
  41. if(!in_array(strtolower(fileext($_FILES['avatar']['name'])),$type))
  42. {
  43. $text=implode(",",$type);
  44. $echo_massage = "您只能上传以下类型文件: ,".$text.",<br>";
  45. }
  46. //生成目标文件的文件名
  47. else{
  48. $filenamea=explode(".",$_FILES['avatar']['name']);
  49. do
  50. {
  51. $filenamea[0]=random(10); //设置随机数长度
  52. $namea=implode(".",$filenamea);
  53. //$name1=$name.".Mcncc";
  54. $uploadfilea=$uploaddir.$namea;
  55. }
  56. while(file_exists($uploadfilea));
  57. if (move_uploaded_file($_FILES['avatar']['tmp_name'],$uploadfilea)){
  58. if($uploadfilea){
  59. $seltuser=mysql_query("update user set name='$name',cellphone='$cellphone',birthday='$birthday',professional='$professional',sex='$sex',avatar='$namea' where id=$user_id_data;")or die(mysql_error());
  60. if($seltuser){
  61. $echo_massage = "您已完善信息!";
  62. }
  63. }
  64. }
  65. }
  66. }
  67. ?>
  68. <div class="message_c_sad" style = 'width: 600px;height: 400px;border: 3px solid #749263;border-radius: 5px;margin: 20px auto;padding: 20px;'>
  69. <?php
  70. if(!$echo_massage) {
  71. echo "您没有上传内容!";
  72. }
  73. else{
  74. echo "$echo_massage";
  75. }
  76. ?>
  77. <p>5秒后将会为您跳转如果您的浏览器没有自动跳转<a href="../page/changemag.php">点击这里</a></p>
  78. </div>
  79. <script>
  80. setTimeout(function(){
  81. history.go(-1);
  82. },5000);
  83. </script>