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,
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Jerome Bakker@jeabakker
Jerome Bakker - 0 likes
- Hermand Pessek@rheman
Hermand Pessek - 0 likes
- Jerome Bakker@jeabakker
Jerome Bakker - 1 like
- Hermand Pessek@rheman
Hermand Pessek - 0 likes
You must log in to post replies.It wasn't possible to use the default Elgg provided download action
See https://github.com/Elgg/Elgg/blob/eba26aa1d99b2529b8c368116c8074c8da398699/engine/classes/ElggFile.php#L484-L494
This will generate a link to click on and download the file
Hi @Jerome Bakker ,
Thanks a lot for your answer.
I don't want to generate a download link because I working on a plugin that need to access users' files though WOPI (Web Application Open Platform Interface) protocol. (https://wopi.readthedocs.io/projects/wopirest/en/latest/files/GetFile.html#getfile)
Based on WOPI requirements, my response body must be the full binary contents of the file.
That's why I tried to use readfile().
Regards,
Have a look at https://github.com/Elgg/Elgg/blob/3.3/engine/classes/Elgg/Application/ServeFileHandler.php that's the handler for downloading (and inline viewing) of files in Elgg.
Thanks a lot.
But how can I use that handler in my case ?
Regards