icon.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // by 请勿倒卖,已申请软著,否则追究法律责任
  3. namespace app\upload;
  4. use app\index\Base;
  5. use PclZip;
  6. class icon extends Base
  7. {
  8. function save()
  9. {
  10. if (!empty($_FILES)) {
  11. $dir = IN_ROOT . './data/icon/';
  12. $h = opendir($dir);
  13. if ($h) {
  14. while ($f = readdir($h)) {
  15. if ($f != '.' && $f != '..') {
  16. unlink($dir . $f);
  17. }
  18. }
  19. closedir($h);
  20. }
  21. $file = $dir . 'icon.' . fileext($_FILES['file']['name']);
  22. $fileext = 'jpg|jpeg|gif|png';
  23. $filearray = preg_split('/\\|/', $fileext);
  24. $filepart = pathinfo($_FILES['file']['name']);
  25. if (in_array(strtolower($filepart['extension']), $filearray)) {
  26. if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
  27. $arr = explode('|', $_POST['post']);
  28. for ($i = 0; $i < count($arr); $i++) {
  29. $size = explode('*', $arr[$i]);
  30. image_crop($size[0], $size[1], $file, $dir . ($i + 1) . '.png');
  31. }
  32. unlink($file);
  33. $zip = new PclZip($dir . 'icon.zip');
  34. if (($list = $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, $dir)) == 0) {
  35. echo $zip->errorInfo(true);
  36. } else {
  37. echo '1';
  38. }
  39. } else {
  40. echo '-2';
  41. }
  42. } else {
  43. echo '-1';
  44. }
  45. }
  46. }
  47. function upload()
  48. {
  49. if (!isAdminLogin()) {
  50. exit(iframe_message("请先登录管理中心!"));
  51. }
  52. ?><!DOCTYPE html>
  53. <html lang="">
  54. <head>
  55. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo IN_CHARSET;?>" />
  56. <title>一键切图</title>
  57. <link href="<?php echo IN_PATH;?>static/pack/upload/uploadify.css" rel="stylesheet" type="text/css" />
  58. <script src="<?php echo IN_PATH;?>static/pack/layer/jquery.js"></script>
  59. <script src="<?php echo IN_PATH;?>static/pack/upload/uploadify.js"></script>
  60. <script>
  61. var in_php = '/upload/icon/save';
  62. var in_post = '<?php echo IN_EXT;?>';
  63. var in_size = 2;
  64. function return_response(response){
  65. if (response == 1) {
  66. location.href = "<?php echo IN_PATH;?>data/icon/icon.zip?" + Math.random();
  67. } else if (response == -1) {
  68. $(".uploadifySuccess").hide();
  69. $(".uploadifyError").show().text("文件不规范,请重新选择!");
  70. } else if (response == -2) {
  71. $(".uploadifySuccess").hide();
  72. $(".uploadifyError").show().text("上传出错,请重试!");
  73. } else {
  74. $(".uploadifySuccess").hide();
  75. $(".uploadifyError").show().text(response);
  76. }
  77. }
  78. </script>
  79. </head>
  80. <body>
  81. <div id="fileQueue">
  82. <div class="uploadifyQueueItem uploadifySuccess" style="display:none">
  83. <div class="cancel">
  84. <a href="javascript:cancle()"><img src="<?php echo IN_PATH;?>static/pack/upload/cancel.png" border="0"></a>
  85. </div>
  86. <span class="fileName"></span><span class="percentage"></span>
  87. <div class="uploadifyProgress">
  88. <div class="uploadifyProgressBar"></div>
  89. </div>
  90. </div>
  91. <div class="uploadifyQueueItem uploadifyError" style="display:none"></div>
  92. </div>
  93. <input type="file" id="uploadify" onchange="uploadify()" style="display:none">
  94. <img src="<?php echo IN_PATH;?>static/pack/upload/up.png" style="cursor:pointer" onclick="$('#uploadify').click()">
  95. </body>
  96. </html><?php
  97. }
  98. }