当前位置: 首页>>代码示例>>PHP>>正文


PHP Uploader::allowed_type方法代码示例

本文整理汇总了PHP中Uploader::allowed_type方法的典型用法代码示例。如果您正苦于以下问题:PHP Uploader::allowed_type方法的具体用法?PHP Uploader::allowed_type怎么用?PHP Uploader::allowed_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Uploader的用法示例。


在下文中一共展示了Uploader::allowed_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

 function _upload_file()
 {
     $ret_info = array();
     // 返回到客户端的信息
     $file = $_FILES['Filedata'];
     if ($file['error'] == UPLOAD_ERR_NO_FILE) {
         $this->json_error('no_upload_file');
         exit;
     }
     import('uploader.lib');
     // 导入上传类
     import('image.func');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     // 限制文件类型
     $uploader->allowed_size(SIZE_GOODS_IMAGE);
     // 限制单个文件大小2M
     $uploader->addFile($file);
     if (!$uploader->file_info()) {
         $this->json_error($uploader->get_error());
         exit;
     }
     /* 取得剩余空间(单位:字节),false表示不限制 */
     $store_mod =& m('store');
     $settings = $store_mod->get_settings($this->store_id);
     $remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $this->mod_uploadedfile->get_file_size($this->store_id) : false;
     /* 判断能否上传 */
     if ($remain !== false) {
         if ($remain < $file['size']) {
             $this->json_error('space_limit_arrived');
             exit;
         }
     }
     /* 指定保存位置的根目录 */
     $uploader->root_dir(ROOT_PATH);
     $filename = $uploader->random_filename();
     /* 上传 */
     $file_path = $uploader->save($this->save_path, $filename);
     // 保存到指定目录
     if (!$file_path) {
         $this->json_error('file_save_error');
         exit;
     }
     $file_type = $this->_return_mimetype($file_path);
     /* 文件入库 */
     $data = array('store_id' => $this->store_id, 'file_type' => $file_type, 'file_size' => $file['size'], 'file_name' => $file['name'], 'file_path' => $file_path, 'belong' => $this->belong, 'item_id' => $this->item_id, 'add_time' => gmtime());
     $file_id = $this->mod_uploadedfile->add($data);
     if (!$file_id) {
         $this->json_error('file_add_error');
         exit;
     }
     if ($this->instance == 'goods_image') {
         /* 生成缩略图 */
         $thumbnail = dirname($file_path) . '/small_' . basename($file_path);
         $bignail = dirname($file_path) . '/big_' . basename($file_path);
         $middlenail = dirname($file_path) . '/middle_' . basename($file_path);
         $smallnail = dirname($file_path) . '/little_' . basename($file_path);
         make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $bignail, 900, 900, THUMB_QUALITY);
         //生成900*900的缩略图
         make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $middlenail, 420, 420, THUMB_QUALITY);
         //生成420*420的缩略图
         make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $smallnail, 60, 60, THUMB_QUALITY);
         //生成60*60的缩略图
         make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY);
         //生成170*170的缩略图
         /* 更新商品相册 */
         $data = array('goods_id' => $this->item_id, 'image_url' => $file_path, 'thumbnail' => $thumbnail, 'bignail' => $bignail, 'middlenail' => $middlenail, 'smallnail' => $smallnail, 'sort_order' => 255, 'file_id' => $file_id);
         if (!$this->mod_goods_image->add($data)) {
             $this->json_error($this->mod_goods_imaged->get_error());
             return false;
         }
         $ret_info = array_merge($ret_info, array('thumbnail' => $thumbnail));
     }
     /* 返回客户端 */
     $ret_info = array_merge($ret_info, array('file_id' => $file_id, 'file_path' => $file_path, 'instance' => $this->instance));
     $this->json_result($ret_info);
 }
开发者ID:184609680,项目名称:wcy_O2O_95180,代码行数:77,代码来源:swfupload.app.php

示例2: uploadfile

 function uploadfile($para)
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(2097152);
     // 2M
     $files = $para;
     //$_FILES['activity_banner'];
     if ($files['error'] == UPLOAD_ERR_OK) {
         /* 处理文件上传 */
         $file = array('name' => $files['name'], 'type' => $files['type'], 'tmp_name' => $files['tmp_name'], 'size' => $files['size'], 'error' => $files['error']);
         $uploader->addFile($file);
         if (!$uploader->file_info()) {
             $data = current($uploader->get_error());
             $res = Lang::get($data['msg']);
             $this->view_iframe();
             echo "<script type='text/javascript'>alert('{$res}');</script>";
             return false;
         }
         $uploader->root_dir(ROOT_PATH);
         $dirname = 'data/files/mall/weixin';
         $filename = $uploader->random_filename();
         $file_path = $uploader->save($dirname, $filename);
     }
     return $file_path;
 }
开发者ID:184609680,项目名称:wcy_O2O_95180,代码行数:28,代码来源:weixin.lib.php

示例3: import

 function _upload_image()
 {
     import('uploader.lib');
     $file = $_FILES['ad_image_file'];
     if ($file['error'] == UPLOAD_ERR_OK) {
         $uploader = new Uploader();
         $uploader->allowed_type(IMAGE_FILE_TYPE);
         $uploader->addFile($file);
         $uploader->root_dir(ROOT_PATH);
         return $uploader->save('data/files/mall/template', $uploader->random_filename());
     }
     return '';
 }
开发者ID:GavinLai,项目名称:ecmall,代码行数:13,代码来源:main.widget.php

示例4: array

 function _upload_file()
 {
     $ret_info = array();
     // 返回到客户端的信息
     $file = $_FILES['Filedata'];
     if ($file['error'] == UPLOAD_ERR_NO_FILE) {
         $this->json_error('no_upload_file');
         exit;
     }
     import('uploader.lib');
     // 导入上传类
     import('image.func');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     // 限制文件类型
     $uploader->allowed_size(2048000);
     // 限制单个文件大小2M
     $uploader->addFile($_FILES['Filedata']);
     if (!$uploader->file_info()) {
         $this->json_error($uploader->get_error());
         exit;
     }
     /* 指定保存位置的根目录 */
     $uploader->root_dir(ROOT_PATH);
     $filename = $uploader->random_filename();
     /* 上传 */
     $file_path = $uploader->save($this->save_path, $filename);
     // 保存到指定目录
     if (!$file_path) {
         $this->json_error('file_save_error');
         exit;
     }
     $thumbnail = dirname($file_path) . '/small_' . basename($file_path);
     make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $thumbnail, 810, "", 85);
     $file_type = $this->_return_mimetype($file_path);
     /* 文件入库 */
     $data = array('store_id' => 0, 'file_type' => $file_type, 'file_size' => $file['size'], 'file_name' => $file['name'], 'thumb_nail' => $thumbnail, 'file_path' => $file_path, 'belong' => $this->belong, 'item_id' => $this->item_id, 'add_time' => gmtime());
     $file_id = $this->mod_uploadedfile->add($data);
     if (!$file_id) {
         $this->json_error('file_add_error');
         return false;
     }
     /* 返回客户端 */
     if ($this->belong == BELONG_CHECK) {
         $ret_info = array('belong' => BELONG_CHECK, 'file_id' => $file_id, 'file_path' => $file_path);
     } else {
         $ret_info = array('file_id' => $file_id, 'file_path' => $file_path);
     }
     $this->json_result($ret_info);
 }
开发者ID:184609680,项目名称:wcy_O2O_95180,代码行数:50,代码来源:swfupload.app.php

示例5: import

 function _upload_image()
 {
     import('uploader.lib');
     $images = array();
     for ($i = 0; $i <= 50; $i++) {
         $file = $_FILES['ad' . $i . '_image_file'];
         if ($file['error'] == UPLOAD_ERR_OK) {
             $uploader = new Uploader();
             $uploader->allowed_type(IMAGE_FILE_TYPE);
             $uploader->addFile($file);
             $uploader->root_dir(ROOT_PATH);
             $images[$i] = $uploader->save('data/files/mall/template', $uploader->random_filename());
         }
     }
     return $images;
 }
开发者ID:dongfeihu,项目名称:estore,代码行数:16,代码来源:main.widget.php

示例6: import

 function _upload_image($num)
 {
     import('uploader.lib');
     $images = array();
     for ($i = 0; $i < $this->_num; $i++) {
         $file = array();
         foreach ($_FILES['ad_image_file'] as $key => $value) {
             $file[$key] = $value[$i];
         }
         if ($file['error'] == UPLOAD_ERR_OK) {
             $uploader = new Uploader();
             $uploader->allowed_type(IMAGE_FILE_TYPE);
             $uploader->addFile($file);
             $uploader->root_dir(ROOT_PATH);
             $images[$i] = $uploader->save('data/files/mall/template', $uploader->random_filename());
         }
     }
     return $images;
 }
开发者ID:BGCX261,项目名称:zmall-svn-to-git,代码行数:19,代码来源:main.widget.php

示例7: upload

 public function upload($upload_file, $type, $size, $url)
 {
     $file = $_FILES[$upload_file];
     // 		if ($file['error']!=0){
     // 			return array('message'=>'请选择文件');
     // 		}
     $uploader = new Uploader();
     if ($type) {
         $uploader->allowed_type($type);
         // 限制文件类型
     }
     if ($size) {
         $uploader->allowed_size($size);
     }
     $uploader->addFile($file);
     if ($uploader->_file['error']) {
         return array('message' => $uploader->_file['error']);
     }
     $newName = $uploader->random_filename();
     //$uploader->root_dir(dirname(Yii::app()->BasePath));
     $uploader->root_dir(Yii::app()->params['uploadPath']);
     $uploader->save($url, $newName);
     return array('filePath' => dirname(Yii::app()->BasePath), 'file' => $url . $newName . '.' . $uploader->_file['extension']);
 }
开发者ID:zwq,项目名称:unpei,代码行数:24,代码来源:UploadFile.php

示例8: import

 /**
  * 上传文件
  *
  */
 function _upload_files()
 {
     import('uploader.lib');
     $data = array();
     /* store_logo */
     $file = $_FILES['store_logo'];
     if ($file['error'] == UPLOAD_ERR_OK && $file != '') {
         $uploader = new Uploader();
         $uploader->allowed_type(IMAGE_FILE_TYPE);
         //$uploader->allowed_size(SIZE_STORE_LOGO); // 20KB
         $uploader->addFile($file);
         if ($uploader->file_info() === false) {
             $this->show_warning($uploader->get_error());
             exit;
         }
         $uploader->root_dir(ROOT_PATH);
         $data['store_logo'] = $uploader->save('data/files/store_' . $this->_store_id . '/other', 'store_logo');
     }
     /* store_banner */
     $file = $_FILES['store_banner'];
     if ($file['error'] == UPLOAD_ERR_OK && $file != '') {
         $uploader = new Uploader();
         $uploader->allowed_type(IMAGE_FILE_TYPE);
         $uploader->allowed_size(SIZE_STORE_BANNER);
         // 200KB
         $uploader->addFile($file);
         if ($uploader->file_info() === false) {
             $this->show_warning($uploader->get_error());
             return false;
         }
         $uploader->root_dir(ROOT_PATH);
         $data['store_banner'] = $uploader->save('data/files/store_' . $this->_store_id . '/other', 'store_banner');
     }
     return $data;
 }
开发者ID:dongfeihu,项目名称:estore,代码行数:39,代码来源:my_store.app.php

示例9: import

 function _upload_logo($brand_id)
 {
     $file = $_FILES['brand_logo'];
     if ($file['error'] == UPLOAD_ERR_NO_FILE || !isset($_FILES['brand_logo'])) {
         return '';
     }
     import('uploader.lib');
     //导入上传类
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     //限制文件类型
     $uploader->addFile($_FILES['brand_logo']);
     //上传logo
     if (!$uploader->file_info()) {
         $this->pop_warning($uploader->get_error());
         if (ACT == 'brand_apply') {
             $m_brand =& m('brand');
             $m_brand->drop($brand_id);
         }
         return false;
     }
     /* 指定保存位置的根目录 */
     $uploader->root_dir(ROOT_PATH);
     /* 上传 */
     if ($file_path = $uploader->save('data/files/mall/brand', $brand_id)) {
         return $file_path;
     } else {
         return false;
     }
 }
开发者ID:184609680,项目名称:wcy_O2O_95180,代码行数:30,代码来源:my_goods.app.php

示例10: import

 /**
  * 上传广告图片
  * @param 无
  * @return bool 上传是否成功
  */
 function _upload_ad_image()
 {
     import('uploader.lib');
     $file = $_FILES['ad_img'];
     //修复tmp_name路径
     $file['tmp_name'] = str_replace("\\\\", "\\", $file['tmp_name']);
     /* 上传图片 */
     if ($file['error'] == UPLOAD_ERR_OK) {
         $uploader = new Uploader();
         $uploader->allowed_type(IMAGE_FILE_TYPE);
         $uploader->addFile($file);
         $uploader->root_dir(ROOT_PATH);
         return $uploader->save('data/files/mall/ad_images', $uploader->random_filename());
     }
     return false;
 }
开发者ID:184609680,项目名称:wcy_O2O_95180,代码行数:21,代码来源:ad.app.php

示例11: import

 /**
  *    上传默认商品图片、默认店铺标志、默认会员头像
  *
  *    @author    Hyber
  *    @param     array  $images
  *    @return    array
  */
 function _upload_images($images)
 {
     import('uploader.lib');
     $image_urls = array();
     foreach ($images as $image) {
         $file = $_FILES[$image];
         if ($file['error'] != UPLOAD_ERR_OK) {
             continue;
         }
         $uploader = new Uploader();
         $uploader->allowed_type(IMAGE_FILE_TYPE);
         $uploader->addFile($file);
         if ($uploader->file_info() === false) {
             continue;
         }
         $uploader->root_dir(ROOT_PATH);
         $image_urls[$image] = $uploader->save(UPLOAD_DIR, $image);
     }
     return $image_urls;
 }
开发者ID:dongfeihu,项目名称:estore,代码行数:27,代码来源:setting.app.php

示例12: import

 /**
  * 上传商品图片
  *
  * @param int $goods_id
  * @return bool
  */
 function _upload_image($goods_id)
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(SIZE_GOODS_IMAGE);
     // 400KB
     /* 取得剩余空间(单位:字节),false表示不限制 */
     $store_mod =& m('store');
     $settings = $store_mod->get_settings($this->_store_id);
     $upload_mod =& m('uploadedfile');
     $remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $upload_mod->get_file_size($this->_store_id) : false;
     $files = $_FILES['new_file'];
     foreach ($files['error'] as $key => $error) {
         if ($error == UPLOAD_ERR_OK) {
             /* 处理文件上传 */
             $file = array('name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'size' => $files['size'][$key], 'error' => $files['error'][$key]);
             $uploader->addFile($file);
             if (!$uploader->file_info()) {
                 $this->_error($uploader->get_error());
                 return false;
             }
             /* 判断能否上传 */
             if ($remain !== false) {
                 if ($remain < $file['size']) {
                     $this->_error('space_limit_arrived');
                     return false;
                 } else {
                     $remain -= $file['size'];
                 }
             }
             $uploader->root_dir(ROOT_PATH);
             $dirname = 'data/files/store_' . $this->_store_id . '/goods_' . time() % 200;
             $filename = $uploader->random_filename();
             $file_path = $uploader->save($dirname, $filename);
             $thumbnail = dirname($file_path) . '/small_' . basename($file_path);
             make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY);
             /* 处理文件入库 */
             $data = array('store_id' => $this->_store_id, 'file_type' => $file['type'], 'file_size' => $file['size'], 'file_name' => $file['name'], 'file_path' => $file_path, 'add_time' => gmtime());
             $uf_mod =& m('uploadedfile');
             $file_id = $uf_mod->add($data);
             if (!$file_id) {
                 $this->_error($uf_mod->get_error());
                 return false;
             }
             /* 处理商品图片入库 */
             $data = array('goods_id' => $goods_id, 'image_url' => $file_path, 'thumbnail' => $thumbnail, 'sort_order' => 255, 'file_id' => $file_id);
             if (!$this->_image_mod->add($data)) {
                 $this->_error($this->_image_mod->get_error());
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:BGCX261,项目名称:zhou3liu-svn-to-git,代码行数:62,代码来源:my_goods.app.php

示例13: import

 function remote_image()
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(SIZE_GOODS_IMAGE);
     // 2M
     $upload_mod =& m('uploadedfile');
     /* 取得剩余空间(单位:字节),false表示不限制 */
     $store_mod =& m('store');
     $settings = $store_mod->get_settings($this->store_id);
     $remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $upload_mod->get_file_size($this->store_id) : false;
     $uploader->root_dir(ROOT_PATH);
     $dirname = '';
     $remote_url = trim($_POST['remote_url']);
     if (!empty($remote_url)) {
         if (preg_match("/^(http:\\/\\/){1,1}.+(gif|png|jpeg|jpg){1,1}\$/i", $remote_url)) {
             $result = $this->url_exist($remote_url, 2097152, $remain);
             if ($result === 1) {
                 $this->view_remote();
                 $res = Lang::get("url_invalid");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             } elseif ($result === 2) {
                 $this->view_remote();
                 $res = Lang::get("not_allowed_size");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             } elseif ($result === 3) {
                 $this->view_remote();
                 $res = Lang::get("space_limit_arrived");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             }
             $img_url = _at('file_get_contents', $remote_url);
             $dirname = '';
             if ($this->belong == BELONG_GOODS) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/goods_' . time() % 200;
             } elseif ($this->belong == BELONG_STORE) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/other';
             } elseif ($this->belong == BELONG_ARTICLE) {
                 $dirname = 'data/files/mall/store_' . $this->visitor->get('manage_store') . '/article';
             }
             $filename = $uploader->random_filename();
             $new_url = $dirname . '/' . $filename . '.' . substr($remote_url, strrpos($remote_url, '.') + 1);
             ecm_mkdir(ROOT_PATH . '/' . $dirname);
             $fp = _at('fopen', ROOT_PATH . '/' . $new_url, "w");
             _at('fwrite', $fp, $img_url);
             _at('fclose', $fp);
             if (!file_exists(ROOT_PATH . '/' . $new_url)) {
                 $this->view_remote();
                 $res = Lang::get("system_error");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             }
             /* 处理文件入库 */
             $data = array('store_id' => $this->store_id, 'file_type' => $this->_return_mimetype(ROOT_PATH . '/' . $new_url), 'file_size' => filesize(ROOT_PATH . '/' . $new_url), 'file_name' => substr($remote_url, strrpos($remote_url, '/') + 1), 'file_path' => $new_url, 'belong' => $this->belong, 'item_id' => $this->id, 'add_time' => gmtime());
             $file_id = $upload_mod->add($data);
             if (!$file_id) {
                 $this->_error($uf_mod->get_error());
                 return false;
             }
             if ($this->instance == 'goods_image') {
                 /* 生成缩略图 */
                 $thumbnail = dirname($new_url) . '/small_' . basename($new_url);
                 make_thumb(ROOT_PATH . '/' . $new_url, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY);
                 /* 更新商品相册 */
                 $mod_goods_image =& m('goodsimage');
                 $goods_image = array('goods_id' => $this->id, 'image_url' => $new_url, 'thumbnail' => $thumbnail, 'sort_order' => 255, 'file_id' => $file_id);
                 if (!$mod_goods_image->add($goods_image)) {
                     $this->_error($this->mod_goods_imaged->get_error());
                     return false;
                 }
                 $data['thumbnail'] = $thumbnail;
             }
             $data['instance'] = $this->instance;
             $data['file_id'] = $file_id;
             $res = "{";
             foreach ($data as $key => $val) {
                 $res .= "\"{$key}\":\"{$val}\",";
             }
             $res = substr($res, 0, strrpos($res, ','));
             $res .= '}';
             $this->view_remote();
             echo "<script type='text/javascript'>window.parent.add_uploadedfile({$res});</script>";
         } else {
             $res = Lang::get('url_invalid');
             $this->view_remote();
             echo "<script type='text/javascript'>alert('{$res}');</script>";
             return false;
         }
     } else {
         $res = Lang::get('remote_empty');
         $this->view_remote();
         echo "<script type='text/javascript'>alert('{$res}');</script>";
         return false;
     }
 }
开发者ID:BGCX261,项目名称:zhou3liu-svn-to-git,代码行数:99,代码来源:comupload.app.php

示例14: import

 /**
  *    处理上传标志
  *
  *    @author    Garbin
  *    @param     int $partner_id
  *    @return    string
  */
 function _upload_logo($partner_id)
 {
     import('uploader.lib');
     //导入上传类
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     //限制文件类型
     $uploader->allowed_size(SIZE_STORE_PARTNER);
     // 100KB
     $uploader->addFile($_FILES['logo']);
     //上传logo
     /* 指定保存位置的根目录 */
     $uploader->root_dir(ROOT_PATH);
     /* 上传 */
     if ($file_path = $uploader->save('data/files/store_' . $this->_store_id . '/partner', $partner_id)) {
         return $file_path;
     } else {
         return false;
     }
 }
开发者ID:woolh,项目名称:Online,代码行数:27,代码来源:my_partner.app.php

示例15: import

 function remote_image()
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(2097152);
     // 400KB
     $upload_mod =& m('uploadedfile');
     $uploader->root_dir(ROOT_PATH);
     $dirname = '';
     $remote_url = trim($_POST['remote_url']);
     if (!empty($remote_url)) {
         if (preg_match("/^(http:\\/\\/){1,1}.+(gif|png|jpeg|jpg){1,1}\$/i", $remote_url)) {
             $result = $this->url_exist($remote_url, 2097152, 0);
             if ($result === 1) {
                 $this->view_iframe();
                 $res = Lang::get("url_invalid");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             } elseif ($result === 2) {
                 $this->view_iframe();
                 $res = Lang::get("not_allowed_size");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             }
             $img_url = @file_get_contents($remote_url);
             $dirname = '';
             if ($this->belong == BELONG_GOODS) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/goods_' . time() % 200;
             } elseif ($this->belong == BELONG_STORE) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/other';
             } elseif ($this->belong == BELONG_ARTICLE) {
                 $dirname = 'data/files/mall/store_' . $this->visitor->get('manage_store') . '/article';
             }
             $filename = $uploader->random_filename();
             $new_url = $dirname . '/' . $filename . '.' . substr($remote_url, strrpos($remote_url, '.') + 1);
             ecm_mkdir(ROOT_PATH . '/' . $dirname);
             $fp = @fopen(ROOT_PATH . '/' . $new_url, "w");
             @fwrite($fp, $img_url);
             @fclose($fp);
             if (!file_exists(ROOT_PATH . '/' . $new_url)) {
                 $this->view_iframe();
                 $res = Lang::get("system_error");
                 echo "<script type='text/javascript'>alert({$res});</script>";
                 return false;
             }
             /* 处理文件入库 */
             $data = array('store_id' => $this->visitor->get('manage_store'), 'file_type' => filetype(ROOT_PATH . '/' . $new_url), 'file_size' => filesize(ROOT_PATH . '/' . $new_url), 'file_name' => substr($remote_url, strrpos($remote_url, '/') + 1), 'file_path' => $new_url, 'belong' => $this->belong, 'item_id' => $this->id, 'add_time' => gmtime());
             $file_id = $upload_mod->add($data);
             if (!$file_id) {
                 $this->_error($uf_mod->get_error());
                 return false;
             }
             $data['file_id'] = $file_id;
             $res = "{";
             foreach ($data as $key => $val) {
                 $res .= "\"{$key}\":\"{$val}\",";
             }
             $res = substr($res, 0, strrpos($res, ','));
             $res .= '}';
             $this->view_iframe();
             echo "<script type='text/javascript'>window.parent.add_uploadedfile({$res});</script>";
         } else {
             $res = Lang::get('url_invalid');
             $this->view_iframe();
             echo "<script type='text/javascript'>alert('{$res}');</script>";
             return false;
         }
     } else {
         $res = Lang::get('remote_empty');
         $this->view_iframe();
         echo "<script type='text/javascript'>alert('{$res}');</script>";
         return false;
     }
 }
开发者ID:zhangxiaoling,项目名称:ecmall,代码行数:76,代码来源:comupload.app.php


注:本文中的Uploader::allowed_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。