function deleteSubCityImage() { $file = $_REQUEST['image']; $file_path = DOC_ROOT . 'uploads/sub-city/' . $file; if (file_exists($file_path)) { if (unlink($file_path)) { $subcity = new SubCity(); $subcity->setSubCityId($_REQUEST['id']); $data = $subcity->getSubCityFromId(); $subcity->extractor($data); $imagelist = $subcity->subCityImage(); $imgs = explode(',', $imagelist); $key = array_search($file, $imgs); if (false !== $key) { unset($imgs[$key]); } for ($x = 0; $x <= count($imgs); $x++) { if (!empty($imgs[$x])) { $update_img .= $imgs[$x] . ','; } } $subcity->setSubCityImage($update_img); $subcity->updateSubCityImages(); Common::jsonSuccess("City Image Deleted Successfully"); } else { Common::jsonError("Fail To Delete"); } } else { Common::jsonError("Error"); } }