Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created July 12, 2019 20:22
Show Gist options
  • Save rpayanm/3741217e008ee9cd1803a3d3e4fddd83 to your computer and use it in GitHub Desktop.
Save rpayanm/3741217e008ee9cd1803a3d3e4fddd83 to your computer and use it in GitHub Desktop.
global $user;
$file = new stdClass();
$file->fid = NULL;
$file->uri = 'private://' . $filename;
$file->filename = $filename;
$file->filemime = file_get_mimetype($file->uri);
$file->uid = $user->uid;
$file->status = 0;
file_save($file);
$headers = file_get_content_headers($file);
$headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"';
file_transfer($file->uri, $headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment