customFileUploadDir . $fileName; } else { list($path, $mimeType) = CRM_Core_BAO_File::path($fileId, $entityId); } $mimeType = CRM_Utils_Request::retrieveValue('mime-type', 'String', $mimeType, FALSE); if (!$path) { CRM_Core_Error::statusBounce('Could not retrieve the file'); } $buffer = file_get_contents($path); if (!$buffer) { CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file'); } if ($action & CRM_Core_Action::DELETE) { if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) { CRM_Core_BAO_File::deleteFileReferences($fileId, $entityId, $fieldId); CRM_Core_Session::setStatus(ts('The attached file has been deleted.'), ts('Complete'), 'success'); $session = CRM_Core_Session::singleton(); $toUrl = $session->popUserContext(); CRM_Utils_System::redirect($toUrl); } } else { CRM_Utils_System::download( CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer, NULL, TRUE, $disposition ); } } }