upload.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * PHP upload demo for Editor.md
  4. *
  5. * @FileName: upload.php
  6. * @Auther: Pandao
  7. * @E-mail: pandao@vip.qq.com
  8. * @CreateTime: 2015-02-13 23:20:04
  9. * @UpdateTime: 2015-02-14 14:52:50
  10. * Copyright@2015 Editor.md all right reserved.
  11. */
  12. //header("Content-Type:application/json; charset=utf-8"); // Unsupport IE
  13. header("Content-Type:text/html; charset=utf-8");
  14. header("Access-Control-Allow-Origin: *");
  15. require("editormd.uploader.class.php");
  16. error_reporting(E_ALL & ~E_NOTICE);
  17. $path = __DIR__ . DIRECTORY_SEPARATOR;
  18. $url = dirname($_SERVER['PHP_SELF']) . '/';
  19. $savePath = realpath($path . '../uploads/') . DIRECTORY_SEPARATOR;
  20. $saveURL = $url . '../uploads/';
  21. $formats = array(
  22. 'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp')
  23. );
  24. $name = 'editormd-image-file';
  25. if (isset($_FILES[$name]))
  26. {
  27. $imageUploader = new EditorMdUploader($savePath, $saveURL, $formats['image'], false); // Ymdhis表示按日期生成文件名,利用date()函数
  28. $imageUploader->config(array(
  29. 'maxSize' => 1024, // 允许上传的最大文件大小,以KB为单位,默认值为1024
  30. 'cover' => true // 是否覆盖同名文件,默认为true
  31. ));
  32. if ($imageUploader->upload($name))
  33. {
  34. $imageUploader->message('上传成功!', 1);
  35. }
  36. else
  37. {
  38. $imageUploader->message('上传失败!', 0);
  39. }
  40. }
  41. ?>