Why isn't my managed file getting saved? Please save me from ripping out the rest of my hair...

I've got a "managed_file" field in a form; nothing special.  When the form is submitted, I run something like the following code to, presumably, catch and save it:

$destination = "public://video_posters";
$file_return = file_save_upload('field_poster_frame', array('file_validate_extensions' =&gt; array('jpg jpeg png gif')), $destination, FILE_EXISTS_RENAME);
if ($file_return) {
     $file_return-&gt;status = FILE_STATUS_PERMANENT;
     file_save($file_return);
     file_usage_add($file_return, 'my_module', 'node', $some_nid);
}


(There is more testing of $file_return to catch the other cases, and a few other things, but you get the idea.)

What's happening is:


An entry shows up in the file_managed table that is correct except that its uri is temporary://the_file_name.jpg instead of, presumably, public://video_posters/the_file_name.jpg.
The file was indeed uploaded and is in the indicated place in temp storage -- just not where I want it to be.


Am I missing something obvious?  Any things to check on?  This is really driving me over the edge.  Thanks!
The managed_file element handles moving the file into place and adding a file record, you don't need to save it yourself. The file module does all this in a validation function which makes the fid available in the submit handler.

So, for example, if your file element is defined with $form['file_id'] = ..., you can change your code to something like the following

$fid = $form_state['values']['file_id'];
$file = file_load($fid);
$file-&gt;status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, 'my_module', 'node', $some_nid);