english/administrator/components/com_aicontactsafe/models/attachments.php
// function to delete one or more attached files
function to delete one or more attached files
function to delete one or more attached files
function delete() {
		$db = &JFactory::getDBO();
		jimport('joomla.filesystem.file');
		$upload_folder = str_replace('\\',DS,$this->_config_values['upload_attachments']);
		$upload_folder = str_replace('/',DS,$upload_folder);
		$upload_folder = str_replace('&#92;',DS,$upload_folder);
		$path_upload = JPATH_ROOT.DS.$upload_folder;
		$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
		JArrayHelper::toInteger($cid);
		foreach($cid as $id) {
			$file_name = JRequest::getCmd( 'file_'.$id, '', 'post');
			$query = 'DELETE FROM #__aicontactsafe_messagefiles WHERE name = \''.$file_name.'\' AND id = '.$id.';';
			$db->setQuery( $query );
			$db->query();
			$file = $path_upload.DS.$file_name;
			if (JFile::exists($file)) {
				JFile::delete($file);
			}
		}
	}
function delete ( ) { $ db = & JFactory :: getDBO ( ) ; jimport ( 'joomla.filesystem.file' ) ; $ upload_folder = str_replace ( '\\' , DS , $ this -> _config_values [ 'upload_attachments' ] ) ; $ upload_folder = str_replace ( '/' , DS , $ upload_folder ) ; $ upload_folder = str_replace ( '&#92;' , DS , $ upload_folder ) ; $ path_upload = JPATH_ROOT . DS . $ upload_folder ; $ cid = JRequest :: getVar ( 'cid' , array ( ) , 'post' , 'array' ) ; JArrayHelper :: toInteger ( $ cid ) ; foreach ( $ cid as $ id ) { $ file_name = JRequest :: getCmd ( 'file_' . $ id , '' , 'post' ) ; $ query = 'DELETE FROM #__aicontactsafe_messagefiles WHERE name = \'' . $ file_name . '\' AND id = ' . $ id . ';' ; $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; $ file = $ path_upload . DS . $ file_name ; if ( JFile :: exists ( $ file ) ) { JFile :: delete ( $ file ) ; } } }
function to delete one or more attached files
function to delete one or more attached files
// initialize the database // import joomla clases to manage file system // get the path to attachments upload // read the ids of the records seleted for deletion // delete files from the database and from the upload folder // get the file name // delete it from the database // delete it from the upload folder