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/amberconcept/create_po.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//include wp libriries and set timezone to HK
require_once('wp-load.php'); 
date_default_timezone_set("Asia/Hong_Kong"); 

$wpdb->insert('custom_po_master', array(
    'po_number' => $_POST['po_number'],
    'po_date' => $_POST['po_date'],
    'vendor_name' => $_POST['vendor_name'],
	'vendor_detail' => $_POST['vendor_detail'],
	'ship_detail' => $_POST['ship_detail'],
	'customer_ship_address' => $_POST['customer_ship_address'],
	'customerName' => $_POST['customerName'],
	'customerAddress' => $_POST['customerAddress'],
	'customerPhone' => $_POST['customerPhone'],
	'courierPayment' => $_POST['courierPayment'],
	'order_id' => $_POST['order_id'],
	'currency' => $_POST['currency'],
	'po_amount' => $_POST['grand_total'],
	'create_by' => get_current_user_id(),
	'modify_by' => get_current_user_id()	
));

$po_id = $wpdb->insert_id;

foreach($_POST['item_sequence'] as $idx=>$sequence_value) {

	//if($sequence_value != "") {
		$wpdb->insert('custom_po_detail', array(
			'po_id' => $po_id,
			'item_name' => stripslashes($_POST['item_name'][$idx]),
			'item_qty' => $_POST['item_qty'][$idx],
			'item_unit_price' => $_POST['item_unit_price'][$idx],
			'item_total' => $_POST['item_total'][$idx],
			'item_sequence' => $sequence_value,
			'item_type' => $_POST['item_type'][$idx],
		));		

		$key = str_replace("PO#","PO",$_POST['po_number'])."-".($idx+1);

		//echo "<br>";

		$directory = "/var/www/html/ossfs/amber/po/".$key;

		//echo "<br>";

		$permissions = 0777; 
		
		if (!is_dir($directory)) {

		//	echo "create directory";
	//		echo "<br>";
			// Create the directory
			if (mkdir($directory, $permissions, true)) {  // 'true' enables recursive creation of parent dirs if needed
	//			echo "change file permission 1";
	//			echo "<br>";
				chmod($directory, $permissions);
			} 
		} else {
	//		echo "change file permission 2";
	//		echo "<br>";			
			chmod($directory, $permissions);
		}
	//}		
}

//create folder in amber PO ftp



echo "<meta http-equiv='refresh' content='0;url=https://www.amberconcept.com/po-new?mode=edit&id=".$po_id."' />";