$name=$_POST;
include ('../PHPExcel.php');
include '../PHPExcel/Writer/Excel2007.php';
require '. ./../../data/config.php';
define('FILE_URL','../../../attachment/');//儲存的路徑
define(" FILE1","../../../FTP_FILE/file1.xlsx");//檔案1 詳細商品資訊
define("FILE2","../../../FTP_FILE/file1 .xlsx");//檔案2 商品來源位址
define("FILE_IMG","../../../FTP_FILE/contentPic/..");//contentPic圖片資料夾
/ / $number=$_POST['number'];//取得人數
// $setime=$_POST['setime'];//取得時間
// print_r($_FILES);//取得檔案路徑等
// move_uploaded_file($_FILES['file_1']['tmp_name'], 'FILE1.xlsx');
//--------------- -------------------------------------------------- ----------------------判斷使用者是否上傳了FILE1和FILE2檔案
if(file_exists("../../../FTP_FILE/ FILE1.xlsx")&&file_exists("../../../FTP_FILE/FILE2.xlsx")){
}else{
echo "對不起檔案不存在,請上傳檔案";
exit;
}
//--------------------------------------- ------------------------------------------------FILE1檔案取得
//循環
$filePath = "../../../FTP_FILE/FILE1.xlsx";
//建立reader物件
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canno)( Excel'; $PHPReader->load($filePath);
/**讀取excel檔案中的第一個工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**取得最大的列號*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
//循環循環讀取每個單元格的內容。注意行從1開始,列從A開始
$cd_array=array();
$arr =array();
$temp=array(
'A'=>'name',
'B'=>'class',
'C'=>'C',
'D'=>'D',
'E' =>'E',
'F' =>'F',
'G'=>'G',
'H'=>'macth',
'I'=>'I',
🎜> 'I'=>'I',
🎜> ' J'=>'number',
'K'=>'K',
'L'=>'L',
'M'=>'M',
'N' =>'N',
'O'=>'O',
'P'=>'P',
'Q'=>'Q',
'R'=>> 'R',
'S'=>'S',
'T'=>'T',
'U'=>'descript',
'V'=>'U'=>'descript',
'V'=>'V ',
'W'=>'W',
'X'=>'X',
'Y'=>'Y',
); 對應//指定產生表對應/指定產生表的陣列欄位名稱
for($rowIndex=4;$rowIndex for($colIndex='A';$colIndex $addr = $colIndex.$rowIndex;
$cell = $currentSheet->getCell($addr)->文字轉換字串
$cell = $cell->__toString();
$arr[$temp[$colIndex]]=$ 🎜> unset( $arr);
}
//------------------------------------- -------------------------------------------------- ------------FILE2檔案取得
$filePath = "../../../FTP_FILE/FILE2.xlsx";
//建立reader物件
$ PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5(pader); ){
echo 'no Excel';
return ;
}
}
}
}
.入檔案
$PHPExcel = $PHPReader->load($filePath);
/**讀取excel檔案中的第一個工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**
/**
取得最大的列號*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow(); / 讀取每個單元格的內容。注意行從1開始,列從A開始
//建立reader物件
$url_array=array();
$arr =array();
for($rowIndex=2;$rowIndex for($rowIndex++){
for($colIndex='A';$colIndex col $addr = $.Index. = $currentSheet->getCell($addr)->getValue();
if($cell instanceof PHPExcel_RichText) //健康轉換字串
$arr[] = $cell;
}
$url_array[] = $arr;
unset($arr);} 1
對 $. ) {
foreach ($url_array as $key1 => $value1) {
努
$cd_array[$key ]['url'] = $value1[1];
}
🎜>$cd_info1=array();
foreach ( $cd_array as $key => $value) {
foreach ($value as $key1 => $value1) {
$key1=='macth'||$key1=='descript'||$key1=='url'||$key1=='name'){
1$cd_info[$1] = $value1; 🎜> }
}
_------------ ---------------- ---------------- -------------------------------------------------- -----------------------------循環所有圖片路徑為陣列
$j=0;//變數
$ arr = array();//數組
$cd_img=array();
foreach($cd_info1 as $key=>$value){
foreach($value as $key1=> $value1){
if($key1=='descript'){
preg_match_all("/]*)s*src= ('|")([^'"]+)('|")/", $text,$matches);
$new_arr0 $arr = array ();
foreach($new_arr as $val)
{
$i = explode('src=',$val)[1];
$arr[] = substr($i },1,strlen($i)-2);
}
$cd_img[]=$arr;
}
// ------ -----------------------------------函數封裝------------- -------------------------1---------
function hover_file($file_url,$file_name){
//判斷並建立資料夾
$y=date('Y',time());//年
$m=date('m',time());
if( !is_dir('../../../attachment/images/'.$y.$m)){
mkdir('../../../attachment/images/'.$y .$m,0777);//建立年+月的資料夾權限為最高
}
//取得圖片路徑並移動
$text=$file_url;//圖片路徑1
// $file_url;
> /圖片路徑2
$text1;
rename(iconv("UTF-8","GBK",$text),iconv("UTF-8","GBK",$text1));
}
//------------------------------------------- -------------------------------------------------- ---把所有的資料加到資料庫
//新增資料
$uid=array() foreach ($cd_info1 as $key => $value ) {
// var_dump($value);
$img_list= $cd_img[$k_n];
//循環儲存詳細資料中的頁面
$ 1 2 =null;
foreach ($img_list as $key3 => $value3) {
$ p 2 p>