Working …
This value you provided is not a number. Please try again.
This value you provided is not an integer. Please try again.
The value entered is not a valid Vanderbilt Medical Record Number (i.e. 4- to 9-digit number, excluding leading zeros). Please try again.
The value you provided must be within the suggested range
The value you provided is outside the suggested range
This value is admissible, but you may wish to double check it.
The value entered must be a time value in the following format HH:MM within the range 00:00-23:59 (e.g., 04:32 or 23:19).
This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now.
This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now.
This field must be a valid email address (like joe@user.com). Please re-enter it now.
The value you provided could not be validated because it does not follow the expected format. Please try again.
Required format:
REDCap Logo
Plugins, Hooks, & External Modules
Developer methods for
Plugins, Hooks, & External Modules
Hook functions

REDCap Developer Tools:
Documentation for Plugins, Hooks, & External Modules

REDCap Version 14.9.1
REDCap::addFileToRepository
(REDCap >= 12.5.0)
REDCap::addFileToRepository — Adds a file to a project's File Repository when provided with the doc_id of an existing file from the REDCap system.
Description
bool REDCap::addFileToRepository ( int $doc_id, int $project_id [, string $comment = NULL] )
Adds a file to a project's File Repository when provided with the doc_id of an existing file from the REDCap system. NOTE: This method should not be used if the file's doc_id is already attached to a File Upload field or to a file in the File Repository. Thus, it is assumed that REDCap::storeFile() or REDCap::copyFile() must always be used prior to REDCap::addFileToField. If you wish to add a file to the File Repository that is already being utilized elsewhere in REDCap (e.g., as an attachment or uploaded to a File Upload field), it is recommended that you first call REDCap::copyFile() to copy the original file, and then call REDCap::addFileToRepository() afterward.
Parameters
doc_id
The doc_id from the redcap_edocs_metadata database table for a stored file in REDCap.
project_id
The project ID number of the REDCap project with which you want to associate this file.
comment (optional)
The text comment that will be associated with the file when viewing it in the File Repository.
Return Values
Returns TRUE if the file was successfully added to the File Repository, and FALSE if not.
Examples
Example #1:
This example illustrates how one might store a local file in the File Repository.
// Store a file, obtain its doc_id, and then store it in the File Repository
$filepath = "/var/www/redcap/myfiles/studyfile003.docx";
$comment = "File for tracking study participants in this project.";
$doc_id = REDCap::storeFile($filepath, $project_id);
REDCap::addFileToRepository($doc_id, $project_id, $comment);
Example #2:
This example illustrates how one might first copy an existing REDCap file and then add the new file to the File Repository.
// Doc_id of the already-existing file
$doc_id = 223;
// Copy the file to create a new one
$new_doc_id = REDCap::copyFile($doc_id, $project_id);
// Now add the new file to the File Repository
$comment = "File for yada yada yada.";
REDCap::addFileToRepository($new_doc_id, $project_id, $comment);
REDCap 14.9.1 - © 2024 Vanderbilt University