upload_admin.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. function alert($msg)
  3. {
  4. global $charset;
  5. header('Content-type: text/html; charset=utf-8');
  6. $json = new Services_JSON();
  7. echo $json->encode(array('error' => 1, 'message' => $msg));
  8. exit();
  9. }
  10. define('IN_MYMPS', true);
  11. define('IN_AJAX', true);
  12. define('IN_JSON', true);
  13. require_once 'JSON.php';
  14. require_once dirname(__FILE__) . '/../global.inc.php';
  15. require_once MYMPS_INC . '/global.php';
  16. require_once MYMPS_DATA . '/config.php';
  17. require_once MYMPS_DATA . '/config.db.php';
  18. require_once MYMPS_INC . '/upfile.fun.php';
  19. require_once MYMPS_INC . '/admin.class.php';
  20. require_once MYMPS_INC . '/db.class.php';
  21. if (!$mymps_admin->mymps_admin_chk_getinfo()) {
  22. alert('您尚未登录管理员,不能上传图片.');
  23. }
  24. $watermark = isset($watermark) ? $watermark : '';
  25. $dopost = isset($dopost) ? $dopost : '';
  26. $imgwidthValue = isset($imgwidthValue) ? $imgwidthValue : 400;
  27. $imgheightValue = isset($imgheightValue) ? $imgheightValue : 300;
  28. $urlValue = isset($urlValue) ? $urlValue : '';
  29. $imgsrcValue = isset($imgsrcValue) ? $imgsrcValue : '';
  30. $imgurl = isset($imgurl) ? $imgurl : '';
  31. $small = isset($small) ? $small : '';
  32. if (empty($_FILES) === false) {
  33. $name_file = 'imgFile';
  34. $size = $mymps_global['cfg_upimg_size'] * 1024;
  35. $upimg_allow = explode(',', $mymps_global['cfg_upimg_type']);
  36. if ($size < $_FILES[$name_file]['size']) {
  37. alert('上传文件应小于' . $mymps_global['cfg_upimg_size'] . 'KB');
  38. }
  39. if (!in_array(FileExt($_FILES[$name_file]['name']), $upimg_allow)) {
  40. alert('系统只允许上传' . $mymps_global['cfg_upimg_type'] . '格式的图片!');
  41. }
  42. if (!preg_match('/^image\\//i', $_FILES[$name_file]['type'])) {
  43. alert('很抱歉,系统无法识别您上传的文件的格式,请换一张图片上传!');
  44. }
  45. $destination = '/editor/' . date('Ym') . '/';
  46. if ($_FILES[$name_file]['name']) {
  47. $mymps_image = start_upload($name_file, $destination, $mymps_global[cfg_upimg_watermark]);
  48. $imgsrcValue = $mymps_image;
  49. $full_litfilename = $full_filename = MYMPS_ROOT . $mymps_image;
  50. $sizes = getimagesize($full_filename);
  51. $imgwidthValue = $sizes[0];
  52. $imgheightValue = $sizes[1];
  53. $imgsize = filesize($full_litfilename);
  54. $db->query('INSERT INTO `' . $db_mymps . 'upload` (title,url,width,height,filesize,uptime,adminid) VALUES (\'' . $mymps_image[0] . '\',\'' . $imgsrcValue . '\',\'' . $imgwidthValue . '\',\'' . $imgheightValue . '\',\'' . $imgsize . '\',\'' . $nowtime . '\',\'' . $admin_id . '\')');
  55. $file_url = $mymps_global[SiteUrl] . $imgsrcValue;
  56. }
  57. header('Content-type: text/html; charset=utf-8');
  58. $json = new Services_JSON();
  59. echo $json->encode(array('error' => 0, 'url' => $file_url));
  60. exit();
  61. }
  62. ?>