Q:

Create a file programmatically

I am working on a cron job that is creating a backup file.  I want to move the file to the private file directory but I am having trouble figuring out how to do this.  The cron job creates a file in a folder called /temp in the root of my site.  I've been trying to use file_save_upload to move the file, but this isn't working
$gzip_file = $_SERVER['DOCUMENT_ROOT'] . '/temp/myfile.gz';
$private_file = 'private://myfolder/myfile.gz';
$drupal_file = file_save_upload($gzip_file,array(),$private_file,FILE_EXISTS_REPLACE);

I am not getting an error and $drupal_file equals false.  The private folder exists and I can write to it with PHP.  Is file_save_upload the wrong function?  What do I need to do instead?

A:

If it's an 'unmanaged' file, i.e one that doesn't have a database entry, you can use either

file_unmanaged_move or
file_unmanaged_save_data 

