##┌────────────────────────────────────────────────┐
## Implode
##└────────────────────────────────────────────────┘
function ConvertImplode($post){
if(empty($post) || !is_array($post)){
return '';
}
$post = array_map('trim', $post);
$post = array_filter($post);
return implode('**', $post);
}
$maymoc1 = ConvertImplode($_POST['maymoc1']);
$maymoc2 = ConvertImplode($_POST['maymoc2']);
$maymoc3 = ConvertImplode($_POST['maymoc3']);
$maymoc4 = ConvertImplode($_POST['maymoc4']);
##┌────────────────────────────────────────────────┐
## upload-image
##└────────────────────────────────────────────────┘
function uploadVerifiedImage($file, $path){
if (!isset($file['tmp_name']) || $file['error'] != 0) {
return '';
}
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$allow = array('jpg','jpeg','png','gif','webp');
if (!in_array($ext, $allow)) {
return '';
}
$filename = time().'_'.mt_rand(1000,9999).'.'.$ext;
if (move_uploaded_file($file['tmp_name'], $path.$filename)) {
return $filename;
}
return '';
}
$path = "uploads/verified/";
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$gate_image = uploadVerifiedImage($_FILES['gate_image'], $path);
$production_image = uploadVerifiedImage($_FILES['production_image'], $path);
$machinery_image = uploadVerifiedImage($_FILES['machinery_image'], $path);
$certificate_file = uploadVerifiedImage($_FILES['certificate_file'], $path);
$video_file = uploadVerifiedImage($_FILES['video_file'], $path);
if($gate_image != ''){
$input_data['gate_image'] = $gate_image;
}
if($production_image != ''){
$input_data['production_image'] = $production_image;
}
if($machinery_image != ''){
$input_data['machinery_image'] = $machinery_image;
}
if($certificate_file != ''){
$input_data['certificate_file'] = $certificate_file;
}
if($video_file != ''){
$input_data['video_file'] = $video_file;
}
##┌────────────────────────────────────────────────┐
## Note: RESULT
##└────────────────────────────────────────────────┘
$input_data = array(
'bangke1' => $bangke1,
'bangke2' => $bangke2,
);
$xsql = "SELECT id FROM api_Vfactory WHERE shopid=".$shopid;
$rs = $db->sql_query($xsql);
if($db->sql_numrows($rs)){
// UPDATE
$sql = "UPDATE api_Vfactory SET "
.$db->sql_build_array('UPDATE', $input_data)
." WHERE shopid=".$shopid;
}else{
// INSERT
$input_data['shopid'] = $shopid;
$input_data['created_at'] = time();
$sql = "INSERT INTO api_Vfactory "
.$db->sql_build_array('INSERT', $input_data);
}
##┌────────────────────────────────────────────────┐
## Note: explode
##└────────────────────────────────────────────────┘
function parseData($value){
return !empty($value) ? explode('**', $value) : array();
}
$data = data__Vfactory($shopid);
extract($data[0]);
$bangke1 = parseData($bangke1);
$bangke2 = parseData($bangke2);
foreach ($bangke1 as $key => $value) {
<tr>
<td>'.$value.'</td>
<td>'.$bangke2[$key].'</td>
</tr>
}
Không có nhận xét nào:
Đăng nhận xét