send file to browser

Hi everyone,

I want to send file (file entity) to a browser.

So I wrote the following code.

$guid = (int)elgg_extract('guid', $vars); 
$entity = get_entity($guid);

$size = $entity->getSize();
$mimetype = $entity->mimetype;

$file_path= $entity->getFilenameOnFilestore();

header('Content-Length: ' . $size);
header('Content-Type: ' . $mimetype);
readfile($file_path);

it works.

But I want to know if this is  the best practice based on elgg requirements ?

Regards,

 

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking