Esempio n. 1
0
$dirName = "./models";
foreachDir($dirName);
?>
		</div>
	</div>
	<!-- upload model file form -->
	<div>
		<hr>
		<h4>上传模版&nbsp;&nbsp;(上传新的模版或替换掉旧的模版)</h4>
		<form action="#tip" method="post" enctype="multipart/form-data">
			<input type="hidden" name="MAX_FILE_SIZE" value="5000000"/> 
			<input type="file" name="modelFile" id="modelFile"/>
			<input type="submit" name="subModel" id = "subModel" value="提交"/>
		</form>
	</div>
	<div id = "tip">
	<?php 
//处理上传模版表单
if (isset($_POST['subModel'])) {
    $modelFile = $_FILES['modelFile'];
    $modelFilePath = loadModel($modelFile);
    isuploadOk($modelFile, $modelFilePath);
}
?>
	</div>
	

</body>


</html>
Esempio n. 2
0
/**
 * @desc 读取excel文件
 * @return array $productMessage 包含excel信息的多维数组
 */
function readExcel()
{
    $productMessage = array();
    //存储所有的excel数据
    $excelFile = $_FILES['excelFile'];
    if (!empty($excelFile)) {
        $excelFilePath = loadExcel($excelFile);
        //上传文件,得到excel文件路径
    } else {
        echo "请选择excel文件";
    }
    $isuploadOk = isuploadOk($excelFile, $excelFilePath);
    //判断是否上传成功
    //如果excel上传成功
    if ($isuploadOk) {
        // Error reporting
        error_reporting(E_ALL);
        ini_set('display_errors', TRUE);
        ini_set('display_startup_errors', TRUE);
        define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : "\n");
        require_once 'Classes/PHPExcel.php';
        //引入类库
        $PHPReader = new PHPExcel_Reader_Excel2007();
        //如果没有选择excel文件
        if (!$PHPReader->canRead($excelFilePath)) {
            $PHPReader = new PHPExcel_Reader_Excel5();
            if (!$PHPReader->canRead($excelFilePath)) {
                echo 'no Excel';
                return;
            }
        }
        $PHPExcel = $PHPReader->load($excelFilePath);
        //传入excel路径,载入该excel
        //sheet 0
        $currentSheet = $PHPExcel->getSheet(0);
        //column Count
        $allColumn = $currentSheet->getHighestColumn();
        //列
        //Row Count
        $allRow = $currentSheet->getHighestRow();
        //行
        /**excel 中需要读的参数**/
        $arrRPProTitle = array();
        //产品标题
        $arrRPVideoUrl = array();
        //视频链接
        $arrRPProDesc = array();
        //产品描述
        $arrRPProPic = array();
        //产品图片
        $arrRPBanner = array();
        //海报图
        $arrRPResultShowPicSrc = array();
        //场景图
        $arrRPProPackage = array();
        //产品包裹
        $arrRPProBrightSpot = array();
        //产品亮点
        $arrRPShoppingDetails = array();
        //购物细节
        $arrRPAAdProBEFORE = array();
        //A类推广产品:连接DB处理前
        $arrRPAAdProBEFORE = array();
        //B类推广产品:连接DB处理前
        $arrRPBCdProBEFORE = array();
        //C类推广产品:连接DB处理前
        $arrRPDAdProBEFORE = array();
        //D类推广产品:连接DB处理前
        $arrRPOters = array();
        //其它
        $arrRPCertificate = array();
        //证书
        $arrRPSamePara = array();
        //共同参数
        $arrRPDiffPara = array();
        //不同参数
        $arrDiffPataTableNum = array();
        //不同参数参数表
        $arrTabTitleA = array();
        $arrTabHeadA = array();
        $arrTabContA = array();
        $arrTabTitleB = array();
        $arrTabHeadB = array();
        $arrTabContB = array();
        $colBIndex = "B";
        //B列
        $colCIndex = "C";
        //C列
        $colDIndex = "D";
        //D列
        $colEIndex = "E";
        //E列
        $colFIndex = "F";
        //E列
        $tableNum = 0;
        //产品一级分类类型数(excel中有多少个参数规格表就是几)
        //开始循环读取每个单元格的内容
        for ($rowIndex = 1; $rowIndex <= $allRow; $rowIndex++) {
            //从第一行开始循环
            for ($colIndex = 'A'; $colIndex <= $allColumn; $colIndex++) {
                //从A列开始循环
                $addr = $colIndex . $rowIndex;
                //单元格地址:列名.行名
                $cell = trim($currentSheet->getCell($addr)->getValue());
                //得到单元格内容,并去掉单元格开头和结尾处的空格
                if ($cell instanceof PHPExcel_RichText) {
                    //处理富文本
                    $cell = $cell->__toString();
                }
                //产品标题
                if ($cell === "产品标题") {
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrRPProTitle[] = $cellBCol;
                }
                //end 产品标题
                //视频链接
                if ($cell === "视频链接") {
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrRPVideoUrl[] = $cellBCol;
                }
                //end 视频链接
                //===============================================
                //产品描述
                if ($cell === "产品描述") {
                    //产品描述内容
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrRPProDesc[] = $cellBCol;
                }
                //end 产品描述
                //===============================================
                //产品图片
                if ($cell === "产品图片") {
                    //产品图片URL
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //产品图片title
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    $arrRPProPic[] = array($cellBCol, $cellCCol);
                }
                //end 产品图片
                //===============================================
                //海报图
                if ($cell === "海报图") {
                    //海报图图片URL
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //海报图跳转Href
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    $arrRPBanner[] = array($cellBCol, $cellCCol);
                }
                //end 海报图
                //===============================================
                //场景图
                if ($cell === "场景图") {
                    //场景图片URL
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrRPResultShowPicSrc[] = $cellBCol;
                }
                //end 场景图
                //===============================================
                //产品包裹
                if ($cell === "产品包裹") {
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrRPProPackage[] = $cellBCol;
                }
                //end 产品包裹
                //===============================================
                //产品亮点
                if ($cell === "产品亮点") {
                    //产品亮点title
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //产品亮点图片
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //产品亮点文本
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    $arrRPProBrightSpot[] = array($cellBCol, $cellCCol, $cellDCol);
                }
                //end 产品亮点
                //===============================================
                //购物细节
                if ($cell === "购物细节") {
                    //购物细节Title
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //购物细节Cont
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //购物细节Pic
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    $arrRPShoppingDetails[] = array($cellBCol, $cellCCol, $cellDCol);
                    //title,cont,pic
                }
                //end 购物细节
                //===============================================
                //A类推广产品
                if ($cell === "A类推广产品") {
                    //标题
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //推广产品Account
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //推广产品ItemNumber
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    //推广产品运费
                    $addrECol = $colEIndex . $rowIndex;
                    $cellECol = trim($currentSheet->getCell($addrECol)->getValue());
                    $arrRPAAdProBEFORE[] = array($cellBCol, $cellCCol, $cellDCol, $cellECol);
                }
                //end A类推广产品
                //===============================================
                //B类推广产品
                if ($cell === "B类推广产品") {
                    //标题
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //推广产品Account
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //推广产品ItemNumber
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    //推广产品运费
                    $addrECol = $colEIndex . $rowIndex;
                    $cellECol = trim($currentSheet->getCell($addrECol)->getValue());
                    $arrRPBAdProBEFORE[] = array($cellBCol, $cellCCol, $cellDCol, $cellECol);
                }
                //end B类推广产品
                //===============================================
                //C类推广产品
                if ($cell === "C类推广产品") {
                    //标题
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //推广产品Account
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //推广产品ItemNumber
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    //推广产品运费
                    $addrECol = $colEIndex . $rowIndex;
                    $cellECol = trim($currentSheet->getCell($addrECol)->getValue());
                    $arrRPCAdProBEFORE[] = array($cellBCol, $cellCCol, $cellDCol, $cellECol);
                }
                //end C类推广产品
                //===============================================
                //D类推广产品
                if ($cell === "D类推广产品") {
                    //标题
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //推广产品Account
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //推广产品ItemNumber
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    //推广产品运费
                    $addrECol = $colEIndex . $rowIndex;
                    $cellECol = trim($currentSheet->getCell($addrECol)->getValue());
                    $arrRPDAdProBEFORE[] = array($cellBCol, $cellCCol, $cellDCol, $cellECol);
                }
                //end D类推广产品
                //===============================================
                //其它
                if ($cell === "其它") {
                    //Title
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //其它图片
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    //其它文本
                    $addrDCol = $colDIndex . $rowIndex;
                    $cellDCol = trim($currentSheet->getCell($addrDCol)->getValue());
                    $arrRPOters[] = array($cellBCol, $cellCCol, $cellDCol);
                }
                //end 其它
                //===============================================
                //证书
                if ($cell === "证书") {
                    //证书Title
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //证书Cont
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    $arrRPCertificate[] = array($cellBCol, $cellCCol);
                }
                //end 证书
                //===============================================
                //共同参数
                if ($cell === "共同参数") {
                    //共同参数参数名name
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //共同参数参数内容cont
                    $addrCCol = $colCIndex . $rowIndex;
                    $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                    $arrRPSamePara[] = array($cellBCol, $cellCCol);
                }
                //end 共同参数
                //===============================================
                //自定义表格	--表标题
                if ($cell === "表标题A") {
                    //表标题
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrTabTitleA[] = $cellBCol;
                }
                //end 自定义表格	--表标题
                //===============================================
                //自定义表格	--表头
                if ($cell === "表头A") {
                    //表头
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //将字符串数值的表头值转为数组
                    $arrTabHeadA = explode(',', $cellBCol);
                    //取出每个表头值的两头的空格
                    foreach ($arrTabHeadA as &$v) {
                        $v = trim($v);
                    }
                }
                //end 自定义表格--表头
                //===============================================
                //自定义表格	--表内容
                if ($cell === "表内容A") {
                    //表内容
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //将字符串数值的表头值转为数组
                    $arrTabContA = explode('\\n', $cellBCol);
                    foreach ($arrTabContA as &$v) {
                        $v = explode(',', $v);
                        foreach ($v as &$vv) {
                            $vv = trim($vv);
                        }
                    }
                }
                //end 自定义表格--表内容
                //===============================================
                //自定义表格	--表标题
                if ($cell === "表标题B") {
                    //表标题
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    $arrTabTitleB[] = $cellBCol;
                }
                //end 自定义表格	--表标题
                //===============================================
                //自定义表格	--表头
                if ($cell === "表头B") {
                    //表头
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //将字符串数值的表头值转为数组
                    $arrTabHeadB = explode(',', $cellBCol);
                    //取出每个表头值的两头的空格
                    foreach ($arrTabHeadB as &$v) {
                        $v = trim($v);
                    }
                }
                //end 自定义表格--表头
                //===============================================
                //自定义表格	--表内容
                if ($cell === "表内容B") {
                    //表内容
                    $addrBCol = $colBIndex . $rowIndex;
                    $cellBCol = trim($currentSheet->getCell($addrBCol)->getValue());
                    //将字符串数值的表头值转为数组
                    $arrTabContB = explode('\\n', $cellBCol);
                    foreach ($arrTabContB as &$v) {
                        $v = explode(',', $v);
                        foreach ($v as &$vv) {
                            $vv = trim($vv);
                        }
                    }
                }
                //end 自定义表格--表内容
                //===============================================
                //	产品分类和小图
                if ($cell === "产品分类") {
                    $rowIndexNext = $rowIndex + 1;
                    //产品分类
                    $addrNextRow = $colIndex . $rowIndexNext;
                    //下一行
                    $cellNextRow = trim($currentSheet->getCell($addrNextRow)->getValue());
                    //classify0
                    //小图
                    $addrNextRowDcol = $colDIndex . $rowIndexNext;
                    //下一行
                    $cellNextRowDcol = trim($currentSheet->getCell($addrNextRowDcol)->getValue());
                    //samllpicSrc
                    $arrRPDiffPara[] = array("0" => $cellNextRow, "2" => $cellNextRowDcol);
                }
                //end 产品分类和小图
                //===============================================
                //不同参数表
                if ($cell === "产品规格") {
                    $rowIndexNext = $rowIndex;
                    do {
                        $rowIndexNext++;
                        $addrNextRow = $colIndex . $rowIndexNext;
                        //下一行
                        $cellNextRow = trim($currentSheet->getCell($addrNextRow)->getValue());
                        //3w//5w
                        $addrCCol = $colCIndex . $rowIndexNext;
                        //C列
                        $cellCCol = trim($currentSheet->getCell($addrCCol)->getValue());
                        //33//55
                        //判断读取多少行二级分类产品规格
                        if (!($cellNextRow === "产品规格" || empty($cellNextRow))) {
                            //0                //1
                            $arrProDiffParaNum[] = array($cellNextRow, $cellCCol);
                            //array(array('3w','33'),array('5w','55'),);
                        }
                    } while (!($cellNextRow === "产品规格" || empty($cellNextRow)));
                    //把二级产品分类数组赋给二级产品分类总数组,并清空二级产品分类数组,准备下次的分类存储
                    $arrDiffPataTableNum[$tableNum] = $arrProDiffParaNum;
                    $arrProDiffParaNum = array();
                    $tableNum++;
                }
                //end -产品规格
                //===============================================
            }
            //end-col(结束列循环)
        }
        //end-row(结束行循环)
        /**整合处理不同参数分类名 小图和不同参数表*/
        $diffParaTableCount = count($arrDiffPataTableNum);
        //产品分类数量//3
        for ($i = 0; $i < $diffParaTableCount; $i++) {
            $arrRPDiffPara[$i][1] = $arrDiffPataTableNum[$i];
        }
        /**查询数据库返回处理后 的推广类产品的数组**/
        $arrRPAAdProAFTER = array();
        $arrRPBAdProAFTER = array();
        $arrRPCAdProAFTER = array();
        $arrRPDAdProAFTER = array();
        if (!empty($arrRPAAdProBEFORE)) {
            $arrRPAAdProAFTER = ADRPProDB($arrRPAAdProBEFORE);
        }
        if (!empty($arrRPBAdProBEFORE)) {
            $arrRPBAdProAFTER = ADRPProDB($arrRPBAdProBEFORE);
        }
        if (!empty($arrRPCAdProBEFORE)) {
            $arrRPCAdProAFTER = ADRPProDB($arrRPCAdProBEFORE);
        }
        if (!empty($arrRPDAdProBEFORE)) {
            $arrRPDAdProAFTER = ADRPProDB($arrRPDAdProBEFORE);
        }
        /**将所有数组整合成一个数组以便返回**/
        $productMessage["产品标题"] = $arrRPProTitle;
        $productMessage["视频链接"] = $arrRPVideoUrl;
        $productMessage["产品描述"] = $arrRPProDesc;
        $productMessage["产品图片"] = $arrRPProPic;
        $productMessage["海报图"] = $arrRPBanner;
        $productMessage["场景图"] = $arrRPResultShowPicSrc;
        $productMessage["产品包裹"] = $arrRPProPackage;
        $productMessage["产品亮点"] = $arrRPProBrightSpot;
        $productMessage["购物细节"] = $arrRPShoppingDetails;
        $productMessage["A类推广产品"] = $arrRPAAdProAFTER;
        $productMessage["B类推广产品"] = $arrRPBAdProAFTER;
        $productMessage["C类推广产品"] = $arrRPCAdProAFTER;
        $productMessage["D类推广产品"] = $arrRPDAdProAFTER;
        $productMessage["其它"] = $arrRPOters;
        $productMessage["证书"] = $arrRPCertificate;
        $productMessage["共同参数"] = $arrRPSamePara;
        $productMessage['不同参数'] = $arrRPDiffPara;
        $productMessage['表标题A'] = $arrTabTitleA;
        $productMessage['表头A'] = $arrTabHeadA;
        $productMessage['表内容A'] = $arrTabContA;
        $productMessage['表标题B'] = $arrTabTitleB;
        $productMessage['表头B'] = $arrTabHeadB;
        $productMessage['表内容B'] = $arrTabContB;
    }
    //end-IF($isuploadO)
    //存储数据到数组后,便可删除excel表
    if (file_exists($excelFilePath)) {
        unlink($excelFilePath);
    }
    //var_dump($productMessage);die;
    return $productMessage;
}