HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/breadsecret.com/upload_transactionreferenceno_excel.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//include wp libriries and set timezone to HK
require_once('wp-load.php'); 
require_once('custom/PHPExcel.php');
date_default_timezone_set("Asia/Hong_Kong"); 
global $wpdb;
$path = "/var/www/html/ossfs/Breadsecret/awb_excel/";

if ($_FILES["excelFile"]["name"] <> ""){
	
	$filename=time()."_".$_FILES["excelFile"]["name"];
	$filepath = $path.$filename;
	if(move_uploaded_file($_FILES["excelFile"]["tmp_name"], $path.$filename)){
		$arr_result['condition'] = 'success';
		$arr_result['message'] = 'upload success';
		
		if(file_exists($filepath)){	
			$arr_data = array(array());
			$xlsObj = PHPExcel_IOFactory::load($filepath);
			$wsObj = $xlsObj->getActiveSheet();	
			
			$maxColIdx = $wsObj->getHighestColumn();
			$maxColNo = PHPExcel_Cell::columnIndexFromString($maxColIdx);
			$maxCol = $maxColNo-1;
			
 			foreach($wsObj->getRowIterator() as $row) {
				 $xlsRow = $row->getRowIndex();
				 if(trim($wsObj->getCellByColumnAndRow(0, $xlsRow)->getFormattedValue())!=""){
					  for($col=0;$col<=$maxCol;$col++){
						$arr_data[$xlsRow][] = trim($wsObj->getCellByColumnAndRow($col, $xlsRow)->getFormattedValue()); 
					  }
				 } 
			}
					
			 //array_shift($arr_data); // remove first empty row
			 
			 if(count($arr_data)>0){

				for($dataRow=1; $dataRow<count($arr_data); $dataRow++){
					$referenceno = $arr_data[$dataRow][1];
					$paymentmethod = $arr_data[$dataRow][4];
					$transactionreferenceno = $arr_data[$dataRow][6];								

					$arr_orderID = explode(" ",$referenceno);
					
					$orderID =  trim(preg_replace('/[^0-9]/', '', $arr_orderID[0]));
										
					update_post_meta($orderID, 'Payment', $paymentmethod);
					update_post_meta($orderID, 'transactionreferenceno', $transactionreferenceno);
					
				}
			
		//	print_r($arr_data);
				$arr_result['condition'] = 'success';
				$arr_result['message'] = 'import success';		

			 }
		} else {
			$arr_result['condition'] = 'fail';
			$arr_result['message'] = 'uploaded file not found';			
		}
		
	} else {
		$arr_result['condition'] = 'fail';
		$arr_result['message'] = 'unable to upload file';
	}
}

echo json_encode($arr_result);
?>