/** * Delete method * * Delete both the record and the file on the server * * @access public * @param string * @return bool */ public function delete($id = null, $cascade = true) { $this->id = $id; if (!$this->exists()) { throw new Exception(__('Invalid file')); } $image = $this->read(null, $id); $fileName = $image['GalleryImage']['filename']; $file = $this->rootPath . ZuhaSet::webrootSubPath($image['GalleryImage']['dir']) . $fileName; if (parent::delete($id)) { if (file_exists($file) && is_file($file)) { unlink($file); // delete the largest file } $small = str_replace($fileName, 'thumb' . DS . 'small' . DS . $fileName, $file); if (file_exists($small) && is_file($small)) { unlink($small); // delete the small thumb } $medium = str_replace($fileName, 'thumb' . DS . 'medium' . DS . $fileName, $file); if (file_exists($medium) && is_file($medium)) { unlink($medium); // delete the medium thumb } $large = str_replace($fileName, 'thumb' . DS . 'large' . DS . $fileName, $file); if (file_exists($large) && is_file($large)) { unlink($large); // delete the medium thumb } return true; } else { throw new Exception(__('Delete failed')); } }