Here is my delete controller function
Code:
public function DeleteById($id)
{
$file = $this->MediaModel->find($id);
if (empty($file))
return redirect()->back();
$file_path = $this->config->storagePath . $file['upload_path'] . '/' . $file['media_name'];
$small_path = $this->config->storagePath . $file['upload_path'] . '/small/' . $file['media_name'];
$medium_path = $this->config->storagePath . $file['upload_path'] . '/medium/' . $file['media_name'];
$extra_medium_path = $this->config->storagePath . $file['upload_path'] . '/extramedium/' . $file['media_name'];
$all_files = array($file_path, $small_path, $medium_path, $extra_medium_path);
// print_r($all_files);
// die;
// $result = $this->MediaModel->delete($id);
foreach ($all_files as $filpath) {
if (is_readable($filpath)) {
unlink($filpath);
$this->MediaModel->delete($id);
}
return redirect('admin/media')->with('message', 'Image Deleted Successfully From Database');
}
return redirect('admin/media')->with('message', 'Image Delete Errors');
}
From this code only main files get deleted but styles files remains undeleted, what i am missing ?