scrawlUp.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. header("Content-Type:text/html;charset=utf-8");
  3. error_reporting( E_ERROR | E_WARNING );
  4. include "Uploader.class.php";
  5. //上传配置
  6. $config = array(
  7. "savePath" => "upload/" , //存储文件夹
  8. "maxSize" => 1000 , //允许的文件最大尺寸,单位KB
  9. "allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ) //允许的文件格式
  10. );
  11. //临时文件目录
  12. $tmpPath = "tmp/";
  13. //获取当前上传的类型
  14. $action = htmlspecialchars( $_GET[ "action" ] );
  15. if ( $action == "tmpImg" ) { // 背景上传
  16. //背景保存在临时目录中
  17. $config[ "savePath" ] = $tmpPath;
  18. $up = new Uploader( "upfile" , $config );
  19. $info = $up->getFileInfo();
  20. /**
  21. * 返回数据,调用父页面的ue_callback回调
  22. */
  23. echo "<script>parent.ue_callback('" . $info[ "url" ] . "','" . $info[ "state" ] . "')</script>";
  24. } else {
  25. //涂鸦上传,上传方式采用了base64编码模式,所以第三个参数设置为true
  26. $up = new Uploader( "content" , $config , true );
  27. //上传成功后删除临时目录
  28. if(file_exists($tmpPath)){
  29. delDir($tmpPath);
  30. }
  31. $info = $up->getFileInfo();
  32. echo "{'url':'" . $info[ "url" ] . "',state:'" . $info[ "state" ] . "'}";
  33. }
  34. /**
  35. * 删除整个目录
  36. * @param $dir
  37. * @return bool
  38. */
  39. function delDir( $dir )
  40. {
  41. //先删除目录下的所有文件:
  42. $dh = opendir( $dir );
  43. while ( $file = readdir( $dh ) ) {
  44. if ( $file != "." && $file != ".." ) {
  45. $fullpath = $dir . "/" . $file;
  46. if ( !is_dir( $fullpath ) ) {
  47. unlink( $fullpath );
  48. } else {
  49. delDir( $fullpath );
  50. }
  51. }
  52. }
  53. closedir( $dh );
  54. //删除当前文件夹:
  55. return rmdir( $dir );
  56. }