123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- class upload_control
- {
- private $store;
- private $store_grade;
- public function __construct()
- {
- }
-
- public function set($key,$value) {
- $this->$key = $value;
- }
- public function set_store($storeid)
- {
- $this->store = $storeid;
- }
- /**
- * 读取
- */
- public function get($key){
- return $this->$key;
- }
- const POST_NAME = 'goods_image';
- private function fill_files($filename)
- {
- if(file_exists(fetch_config::tmp_file)) {
- unlink(fetch_config::tmp_file);
- }
- copy($filename,fetch_config::tmp_file);
- if(empty($_FILES['goods_image'])) {
- $_FILES['goods_image'] = array();
- }
- $post_info = &$_FILES['goods_image'];
- $path_info = pathinfo($filename);
- $post_info['path'] = $filename;
- $post_info['name'] = $path_info['basename'];
- $post_info['type'] = 'image/'.$path_info['extension'];
- $post_info['error'] = 0;
- $post_info['size'] = filesize($filename);
- $post_info['tmp_name'] = fetch_config::tmp_file;
- }
- public function upload_img($file)
- {
- // 判断图片数量是否超限
- $model_album = Model('album');
- // 上传图片
- $upload = new upload_file();
- $upload->set('default_dir', ATTACH_GOODS . DS . $this->store . DS . $upload->getSysSetPath());
- $upload->set('max_size', C('image_max_filesize'));
- $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
- $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
- $upload->set('thumb_ext', GOODS_IMAGES_EXT);
- $upload->set('fprefix', $this->store);
- $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
- $this->fill_files($file);
- $result = $upload->upfile(upload_control::POST_NAME);
- if (!$result) {
- if (strtoupper(CHARSET) == 'GBK') {
- $upload->error = Language::getUTF8($upload->error);
- }
- $output = array();
- $output['error'] = $upload->error;
- $output = json_encode($output);
- if(is_mobile()) {
- return false;
- }
- else {
- exit($output);
- }
- }
- $img_path = $upload->getSysSetPath() . $upload->file_name;
- // 取得图像大小
- list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $this->store . DS . $img_path);
- // 存入相册
- $image = explode('.', $_FILES[upload_control::POST_NAME]["name"]);
- $insert_array = array();
- $insert_array['apic_name'] = $image['0'];
- $insert_array['apic_tag'] = '';
- $insert_array['aclass_id'] = $this->store;//$class_info['aclass_id'];
- $insert_array['apic_cover'] = $img_path;
- $insert_array['apic_size'] = intval($_FILES[upload_control::POST_NAME]['size']);
- $insert_array['apic_spec'] = $width . 'x' . $height;
- $insert_array['upload_time'] = time();
- $insert_array['store_id'] = $this->store;
- $model_album->addPic($insert_array);
- return $upload->file_name;
- }
- }
|