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


PHP Import::excel方法代码示例

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


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

示例1: ajax_upload_vgoods_sn

 function ajax_upload_vgoods_sn($filename = "", $rt = array())
 {
     @set_time_limit(600);
     //最大运行时间
     $gid = $rt['gid'];
     $fop = Import::fileop();
     unset($rt);
     $vgoods_type = $this->App->findvar("SELECT vgoods_type FROM `{$this->App->prefix()}userconfig` WHERE type = 'basic' LIMIT 1");
     if (!empty($_FILES[$filename]['tmp_name'])) {
         $yuming = str_replace(array('www', '.'), '', $_SERVER["HTTP_HOST"]);
         if (!empty($yuming)) {
             $yuming = $yuming . DS;
         }
         $fn = SYS_PATH . 'cache' . DS . $yuming . 'vgoods' . DS . 'vgoodssn.xls';
         if (file_exists($fn)) {
             unlink($fn);
         }
         //删除原来文件
         $fop->copyfile($filename, $fn);
         //复制文件到服务器
         if (!file_exists($fn)) {
             $fop->copyfile($filename, $fn);
             if (!file_exists($fn)) {
                 echo '<script> alert("上传时发生意外错误!"); </script>';
                 return false;
             }
         }
         $data = Import::excel();
         $data->read($fn);
         //读取文件
         $importkey = $data->sheets[0]['cells'][1];
         for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
             $rD = array();
             for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
                 $rD[] = $data->sheets[0]['cells'][$i][$j];
             }
             if (empty($rD[0])) {
                 continue;
             }
             $rtd = array();
             $rtd['goods_id'] = $gid;
             if ($vgoods_type == '2') {
                 $rtd['goods_pass'] = $rD[0];
                 $sn = $rD[0];
             } else {
                 $rtd['goods_pass'] = $rD[1];
                 $rtd['goods_sn'] = $rD[0];
                 $sn = $rD[1];
             }
             $rtd['addtime'] = mktime();
             $sql = "SELECT id FROM `{$this->App->prefix()}goods_sn` WHERE goods_id='{$gid}' AND goods_pass='{$sn}' LIMIT 1";
             $id = $this->App->findvar($sql);
             if ($id > 0) {
                 continue;
             }
             $this->App->insert('goods_sn', $rtd);
         }
         echo '<script> alert("上传成功!");</script>';
         return false;
     }
     echo '<script> alert("上传失败!");</script>';
     return true;
 }
开发者ID:zhaoshengloveqingqing,项目名称:fenxiao,代码行数:63,代码来源:controller.php

示例2: ajax_upload

 function ajax_upload($filename = "")
 {
     $uid = $this->Session->read('User.uid');
     $rank = $this->Session->read('User.rank');
     $active = $this->App->findvar("SELECT active FROM `{$this->App->prefix()}user` WHERE user_id='{$uid}'");
     $this->Session->write('User.active', $active);
     if ($active != '1') {
         echo '<script> alert("抱歉,你账户处于失活状态,请联系管理员激活!"); </script>';
         return false;
     }
     if (!($uid > 0) || $rank != '10') {
         echo '<script> alert("抱歉,你没有权限上传!"); </script>';
         return false;
     }
     $fop = Import::fileop();
     $fn = SYS_PATH . 'cache' . DS . 'admin-' . $uid . '.php';
     $fop->writefile($fn, "");
     $tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 200;
     $th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 200;
     $tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 450;
     $th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 450;
     if (!empty($_FILES[$filename]['tmp_name'])) {
         $fn = SYS_PATH . 'cache' . DS . 'admin-upload-' . $uid . '.xls';
         if (file_exists($fn)) {
             unlink($fn);
         }
         //删除原来文件
         $fop->copyfile($filename, $fn);
         //复制文件到服务器
         if (!file_exists($fn)) {
             $fop->copyfile($filename, $fn);
             if (!file_exists($fn)) {
                 echo '<script> alert("上传时发生意外错误!"); </script>';
                 return false;
             }
         }
         $data = Import::excel();
         $data->read($fn);
         //读取文件
         $importkey = $data->sheets[0]['cells'][1];
         for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
             //以下注释的for循环打印excel表数据
             $this->rtData = array();
             //商品数据
             $this->rtData_gallery = array();
             //商品相册
             for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
                 $this->goods_key($importkey[$j], $data->sheets[0]['cells'][$i][$j]);
                 //传送 键=>值 处理
             }
             $this->rtData['is_on_sale'] = '0';
             $this->rtData['add_time'] = mktime();
             $this->rtData['uid'] = $uid;
             $inData = $this->rtData;
             //print_r($inData); exit;
             $goods_id = 0;
             //检查该商品已经存在数据库中
             $sn = $inData['goods_sn'];
             //优先级是商品条形码检查
             if (!empty($sn)) {
                 $sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE goods_sn='{$sn}'";
                 $goods_id = $this->App->findvar($sql);
                 //if(!empty($snvar)) continue;
             }
             /*else{
             			$sa = $inData['goods_name']; //商品名称检查是否该商品已经存在
             			if(!empty($sa)){ //最后更新:2012-12-11 10:26
             				$sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE goods_name='$sa'";
             				$goods_id = $this->App->findvar($sql);
             				//if(!empty($savar)) continue;
             			}
             		}*/
             if (!empty($inData['goods_name'])) {
                 //商品图片
                 $val = $inData['original_img'];
                 if (!empty($val)) {
                     $pa = dirname($val);
                     $thumb = basename($val);
                     if (is_file(SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb)) {
                         $pp = SYS_PATH . $pa . DS . 'thumb_s' . DS . mktime() . $thumb;
                         $pps = $pa . '/thumb_s/' . mktime() . $thumb;
                     } else {
                         $pp = SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb;
                         $pps = $pa . '/thumb_s/' . $thumb;
                     }
                     Import::img()->thumb(SYS_PATH . $val, $pp, $tw_s, $th_s);
                     //小缩略图
                     $inData['goods_thumb'] = $pps;
                     if (is_file(SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb)) {
                         $pp = SYS_PATH . $pa . DS . 'thumb_b' . DS . mktime() . $thumb;
                         $pps = $pa . '/thumb_b/' . mktime() . $thumb;
                     } else {
                         $pp = SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb;
                         $pps = $pa . '/thumb_b/' . $thumb;
                     }
                     Import::img()->thumb(SYS_PATH . $val, $pp, $tw_b, $th_b);
                     //大缩略图
                     $inData['goods_img'] = $pps;
                 }
                 if ($goods_id > 0) {
//.........这里部分代码省略.........
开发者ID:zhaoshengloveqingqing,项目名称:fenxiao,代码行数:101,代码来源:controller.php


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