function deleteMainCityImage() { $file = $_REQUEST['image']; $file_path = DOC_ROOT . 'uploads/main-city/' . $file; if (file_exists($file_path)) { if (unlink($file_path)) { $maincity = new MainCity(); $maincity->setMainCityId($_REQUEST['id']); $data = $maincity->getMainCityFromId(); $maincity->extractor($data); $imagelist = $maincity->mainCityImage(); $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] . ','; } } $maincity->setMainCityImage($update_img); $maincity->updateMainCityImages(); Common::jsonSuccess("City Image Deleted Successfully"); } else { Common::jsonError("Fail To Delete"); } } else { Common::jsonError("Error"); } }