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' => array('jpg jpeg png gif')), $destination, FILE_EXISTS_RENAME);
if ($file_return) {
$file_return->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 istemporary://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!