Programmatically save file into profile2 entity I'm trying to save a file into my Profile2 entity, I've taken the user through a multi-step form, I've saved all the data and at the point I want to input my data into my profile object, I have a variable which 'holds' the file object which has already been uploaded before this point. 

However, I can't find out what code I need to run to tell my profile2 entity (in pseudo terms)

field_cover_letter = $file

I've tried opening up a profile object of an existing account to see what it saves it as, which it seems to just be an array of the file object as well, but I tried typecasting my object to an array and using those values, but it throws a PDO. There must be a simple command to add a file to the profile2 object?

Cheers
If you are working with an unmanaged file, the following three-step process should do the trick:


Move the file (if necessary) to its final home defined by the file field on the entity.
Create a file object (see file_save_data() for some hints on how to do this) and then save it using file_save().  This will turn the file from unmanaged to managed.
Add the file reference to the file field.  You may also want to add an entry in the file usage table by calling file_usage_add().  Here is a code snippet for adding a file object to a file field on a node.

$node->file_field_name[LANGUAGE_NONE][0] = array(
  'fid' => $saved_file_object->fid,
  'display' => 1,
  'description' => '',
);


This assumes the file field accepts only one entry (index 0).