function artifactfile_to_soap($file_id, Artifact $artifact, $set_bin_data) { $return = null; $attachedfiles_arr = $artifact->getAttachedFiles(); $rows = db_numrows($attachedfiles_arr); for ($i = 0; $i < $rows; $i++) { $file = array(); $attachment_id = db_result($attachedfiles_arr, $i, 'id'); $file['id'] = $attachment_id; $file['artifact_id'] = db_result($attachedfiles_arr, $i, 'artifact_id'); $file['filename'] = db_result($attachedfiles_arr, $i, 'filename'); $file['description'] = SimpleSanitizer::unsanitize(db_result($attachedfiles_arr, $i, 'description')); if ($set_bin_data) { $attachment_path = ArtifactFile::getPathOnFilesystem($artifact, $attachment_id); if (is_file($attachment_path)) { $file['bin_data'] = file_get_contents($attachment_path); } else { $file['bin_data'] = db_result($attachedfiles_arr, $i, 'bin_data'); } } $file['filesize'] = db_result($attachedfiles_arr, $i, 'filesize'); $file['filetype'] = db_result($attachedfiles_arr, $i, 'filetype'); $file['adddate'] = db_result($attachedfiles_arr, $i, 'adddate'); $file['submitted_by'] = db_result($attachedfiles_arr, $i, 'user_name'); if ($file['id'] == $file_id) { $return = $file; } } return $return; }
$sql = "SELECT description,bin_data,filename,filesize,filetype FROM artifact_file WHERE id='" . db_ei($id) . "' AND artifact_id ='" . db_ei($artifact_id) . "'"; //echo $sql; $result = db_query($sql); if ($result && db_numrows($result) > 0) { if (db_result($result, 0, 'filesize') == 0) { exit_error($Language->getText('global', 'error'), $Language->getText('tracker_download', 'file_is_null')); } else { // Download the patch with the correct filetype require_once 'common/include/Codendi_HTTPPurifier.class.php'; $http = Codendi_HTTPPurifier::instance(); header('X-Content-Type-Options: nosniff'); header('Content-Type: ' . $http->purify(db_result($result, 0, 'filetype'))); header('Content-Length: ' . $http->purify(db_result($result, 0, 'filesize'))); header('Content-Disposition: attachment; filename="' . $http->purify(db_result($result, 0, 'filename')) . '"'); header('Content-Description: ' . $http->purify(db_result($result, 0, 'description'))); $attachment_path = ArtifactFile::getPathOnFilesystem($a, $id); if (is_file($attachment_path)) { readfile($attachment_path); } else { echo db_result($result, 0, 'bin_data'); } exit; } } } else { exit_error($Language->getText('global', 'error'), $Language->getText('global', 'perm_denied')); } } else { exit_error($Language->getText('global', 'error'), $Language->getText('global', 'perm_denied')); } }