123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- // by 请勿倒卖,已申请软著,否则追究法律责任
- namespace app\upload;
- use app\index\Base;
- use PclZip;
- class icon extends Base
- {
- function save()
- {
- if (!empty($_FILES)) {
- $dir = IN_ROOT . './data/icon/';
- $h = opendir($dir);
- if ($h) {
- while ($f = readdir($h)) {
- if ($f != '.' && $f != '..') {
- unlink($dir . $f);
- }
- }
- closedir($h);
- }
- $file = $dir . 'icon.' . fileext($_FILES['file']['name']);
- $fileext = 'jpg|jpeg|gif|png';
- $filearray = preg_split('/\\|/', $fileext);
- $filepart = pathinfo($_FILES['file']['name']);
- if (in_array(strtolower($filepart['extension']), $filearray)) {
- if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
- $arr = explode('|', $_POST['post']);
- for ($i = 0; $i < count($arr); $i++) {
- $size = explode('*', $arr[$i]);
- image_crop($size[0], $size[1], $file, $dir . ($i + 1) . '.png');
- }
- unlink($file);
- $zip = new PclZip($dir . 'icon.zip');
- if (($list = $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, $dir)) == 0) {
- echo $zip->errorInfo(true);
- } else {
- echo '1';
- }
- } else {
- echo '-2';
- }
- } else {
- echo '-1';
- }
- }
- }
- function upload()
- {
- if (!isAdminLogin()) {
- exit(iframe_message("请先登录管理中心!"));
- }
- ?><!DOCTYPE html>
- <html lang="">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=<?php echo IN_CHARSET;?>" />
- <title>一键切图</title>
- <link href="<?php echo IN_PATH;?>static/pack/upload/uploadify.css" rel="stylesheet" type="text/css" />
- <script src="<?php echo IN_PATH;?>static/pack/layer/jquery.js"></script>
- <script src="<?php echo IN_PATH;?>static/pack/upload/uploadify.js"></script>
- <script>
- var in_php = '/upload/icon/save';
- var in_post = '<?php echo IN_EXT;?>';
- var in_size = 2;
- function return_response(response){
- if (response == 1) {
- location.href = "<?php echo IN_PATH;?>data/icon/icon.zip?" + Math.random();
- } else if (response == -1) {
- $(".uploadifySuccess").hide();
- $(".uploadifyError").show().text("文件不规范,请重新选择!");
- } else if (response == -2) {
- $(".uploadifySuccess").hide();
- $(".uploadifyError").show().text("上传出错,请重试!");
- } else {
- $(".uploadifySuccess").hide();
- $(".uploadifyError").show().text(response);
- }
- }
- </script>
- </head>
- <body>
- <div id="fileQueue">
- <div class="uploadifyQueueItem uploadifySuccess" style="display:none">
- <div class="cancel">
- <a href="javascript:cancle()"><img src="<?php echo IN_PATH;?>static/pack/upload/cancel.png" border="0"></a>
- </div>
- <span class="fileName"></span><span class="percentage"></span>
- <div class="uploadifyProgress">
- <div class="uploadifyProgressBar"></div>
- </div>
- </div>
- <div class="uploadifyQueueItem uploadifyError" style="display:none"></div>
- </div>
- <input type="file" id="uploadify" onchange="uploadify()" style="display:none">
- <img src="<?php echo IN_PATH;?>static/pack/upload/up.png" style="cursor:pointer" onclick="$('#uploadify').click()">
- </body>
- </html><?php
- }
- }
|