예제 #1
0
 public function water_upload()
 {
     $typetmp = explode('.', $_FILES['Filedata']['name']);
     $filetype = strtolower($typetmp[count($typetmp) - 1]);
     //验证文印图片格式
     include_once CUR_CONF_PATH . 'lib/cache.class.php';
     $this->cache = new cache();
     $material_type = $this->cache->check_cache('material_type.cache.php');
     $type = '';
     if (!empty($material_type)) {
         foreach ($material_type as $k => $v) {
             if (in_array($filetype, array_keys($v))) {
                 $type = $k;
             }
         }
     }
     if ($type != 'img') {
         return false;
     }
     $filename = date('YmdHis') . hg_generate_user_salt(4) . '.' . $filetype;
     //上传到临时目录
     $path = hg_getimg_default_dir() . MATERIAL_TMP_PATH;
     if (!hg_mkdir($path)) {
         return false;
     } else {
         if (!move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename)) {
             return false;
         } else {
             $info['filename'] = $filename;
             $info['path'] = MATERIAL_TMP_PATH;
             $info['url'] = hg_material_link(hg_getimg_default_host(), MATERIAL_TMP_PATH, '', $filename);
             return $info;
         }
     }
 }
예제 #2
0
 private function addMaterialNodb_file()
 {
     $dir = urldecode($this->input['dir']);
     $name = $this->input['name'];
     $dir[strlen($dir) - 1] == '/' ? $dir = $dir : ($dir = $dir . '/');
     if ($_FILES['Filedata']) {
         if ($_FILES['Filedata']['error']) {
             return false;
         } else {
             if (!$name) {
                 $filename = $_FILES['Filedata']['name'];
             } else {
                 $filename = $name;
             }
             $path = hg_getimg_default_dir() . $dir;
             if (!hg_mkdir($path)) {
                 return false;
             } else {
                 if (file_exists($path . $filename)) {
                     $json = preg_replace('/(.*?\\.).*?/siU', "\\1json", $filename);
                     if (file_exists($path . $json)) {
                         $info = json_decode(file_get_contents($path . $json), true);
                         if (!empty($info['thumb'])) {
                             foreach ($info['thumb'] as $k => $v) {
                                 if (is_file($v) && file_exists($v)) {
                                     @unlink($v);
                                 }
                             }
                         }
                     }
                 }
                 if (!move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename)) {
                     return false;
                 } else {
                     $info = array();
                     $info['host'] = hg_getimg_default_host();
                     $info['dir'] = $dir;
                     $info['filename'] = $filename;
                     return $info;
                 }
             }
         }
     }
 }