Friday 13 December 2013

Delete file/image in cakephp


Delete images in cakephp For instance, you would like to delete car.jpg under YOUR WEBROOT/img folder.
First, you construct a File object:
App::uses('File', 'Utility');

$file = new File(WWW_ROOT .'img/car.jpg',false, 0777);

if($file->delete()){
   echo "file/image deleted successfully";
}else{
   echo "file/image failed to be delete";
}
$file->delete() return true when the file has successfully been deleted. Hence, we check for successions of file deletion using the if statement as shown above.
*** I hope this Post helps to You ***