PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/Ajax_Upload/File.php

https://github.com/jefferkim/jefferCMS
PHP | 107 lines | 86 code | 21 blank | 0 comment | 10 complexity | b6465d224c8ac20f74fcb64acce294f5 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. </head>
  6. <body>
  7. <?
  8. include_once("../config.php");
  9. $sort=12;
  10. $f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
  11. $file_size_max=200*1024*1024;//限制单个文件上传最大容量
  12. $overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
  13. $f_input="Files";//设置上传域名称
  14. foreach($_FILES[$f_input]["error"] as $key => $error){
  15. $up_error="no";
  16. if ($error == UPLOAD_ERR_OK){
  17. $f_name=$_FILES[$f_input]['name'][$key];//获取上传源文件名
  18. $uploadfile=$uploaddir.strtolower(basename($f_name));
  19. $tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
  20. $tmp_type=strtolower($tmp_type);
  21. if(!stristr($f_type,$tmp_type)){
  22. echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
  23. $up_error="yes";
  24. }
  25. if ($_FILES[$f_input]['size'][$key]>$file_size_max) {
  26. echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_FILES[$f_input]
  27. ['size'][$key]/1024)."Kb,大于规定的".($file_size_max/1024)."Kb,上传失败!')</script>";
  28. $up_error="yes";
  29. }
  30. if (file_exists($uploadfile)&&!$overwrite){
  31. echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
  32. $up_error="yes";
  33. }
  34. $string = 'abcdefghijklmnopgrstuvwxyz0123456789';
  35. $rand = '';
  36. for ($x=0;$x<12;$x++)
  37. $t=date("YmdHis").rand(10,99);
  38. $attdir="../../upload/";
  39. if(!is_dir($attdir))
  40. { mkdir($attdir);}
  41. $uploadfile=$attdir.$t.".".$tmp_type;
  42. $filename=$t.".".$tmp_type;
  43. $called=$_POST['called'];
  44. $language=$_POST['language'];
  45. $type=$_POST['type'];
  46. $pictypeRs = $SysConfig['customerdb']->Execute("SELECT Called FROM t_pictype where id='".$type."'");
  47. if ($pictypeRs->RecordCount() >0)
  48. {
  49. $typename = $pictypeRs->fields['Called'];
  50. }
  51. $picRs = $SysConfig['customerdb']->Execute("SELECT OrderBy,id FROM t_pic ORDER BY OrderBy DESC LIMIT 0,1");
  52. $count=count($picRs);
  53. if ($picRs->RecordCount() >0)
  54. {
  55. $orderBy = $picRs->fields['OrderBy'] + 1;
  56. $picid=$picRs->fields['id'] + 1;
  57. }else{
  58. $orderBy=1;
  59. $picid=1;
  60. }
  61. $record = array(
  62. 'id' => $picid,
  63. 'PicName' => $typename,
  64. 'PicUrl' => $filename,
  65. 'BigUrl' => $filename,
  66. 'TypeID' => $type,
  67. 'IsShow' => '1',
  68. 'IsCommend' => '0',
  69. 'OrderBy' => $orderBy,
  70. 'NoteTime' => date("Y-m-d H:i:s"),
  71. 'Language' => $language
  72. );
  73. $SysConfig['customerdb']->AutoExecute("t_pic",$record,"INSERT");
  74. if(($up_error!="yes") and (move_uploaded_file($_FILES[$f_input]['tmp_name']
  75. [$key], $uploadfile))){
  76. $_msg=$_msg.$f_name.'上传成功\n';
  77. }
  78. else{
  79. $_msg=$_msg.$f_name.'上传失败\n';
  80. }
  81. }
  82. }
  83. echo "<script>window.parent.Finish('".$_msg."');</script>";
  84. ?>
  85. </body>
  86. </html>