fileExistsInPath cakePHP function to check if File/Image Exists in valid Path
Saturday, February 13, 2010 13:01Posted in category cakePHP Interview Questions
No Comments
function deletephotograph($id){
//Get File/Image name
$data = $this->Propphotograph->find('first', array('conditions' => array('Propphotograph.id' => $id), 'fields' => array('Propphotograph.photograph')));
$image_name = $data['Propphotograph']['photograph'];
// Use fileExistsInPath() function to check valid File/Image Path
$thumbPath = 'img/props_photographs/thumbs/'.$image_name.'';
$imagePath = 'img/props_photographs/'.$image_name.'';
if (fileExistsInPath($imagePath)){unlink($imagePath);} // Delete Image if it exists
if (fileExistsInPath($thumbPath)){unlink($thumbPath);} // Delete Image Thumb if it exists
$this->Propphotograph->delete($id); // Delete Record
$this->Session->setFlash('The photograph has been deleted.');
$this->redirect($this->referer());
}
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.


